-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support core-js >=2.0.0 < 4.0.0 (#246)
- Loading branch information
Showing
8 changed files
with
135 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
describe('importing ES6 reflect', () => { | ||
|
||
let setMocks = () => { | ||
jest.mock('@angular/core/testing', () => ({ getTestBed: () => ({ initTestEnvironment() { } }) }), { virtual: true }) | ||
jest.mock('@angular/platform-browser-dynamic/testing', () => ({ BrowserDynamicTestingModule: null, platformBrowserDynamicTesting: () => { } }), { virtual: true }) | ||
jest.mock('zone.js/dist/zone.js', () => true, { virtual: true }); | ||
jest.mock('zone.js/dist/proxy.js', () => true, { virtual: true }); | ||
jest.mock('zone.js/dist/sync-test', () => true, { virtual: true }); | ||
jest.mock('zone.js/dist/async-test', () => true, { virtual: true }); | ||
jest.mock('zone.js/dist/fake-async-test', () => true, { virtual: true }); | ||
jest.mock('../zone-patch', () => true, { virtual: true }); | ||
|
||
jest.mock('core-js/es7/reflect', () => true, { virtual: true }); | ||
jest.mock('core-js/proposals/reflect-metadata', () => true, { virtual: true }); | ||
} | ||
|
||
let coreJs2Error = new Error('core-js@3 es6 reflect failed'); | ||
let coreJs3Error = new Error('core-js@2 es6 reflect failed'); | ||
|
||
beforeEach(() => setMocks()); | ||
afterEach(() => jest.resetAllMocks()); | ||
|
||
it('should throw if core-js es6-reflect is not installed', () => { | ||
jest.mock('core-js/es6/reflect', () => { throw coreJs2Error }, { virtual: true }); | ||
jest.mock('core-js/es/reflect', () => { throw coreJs3Error }, { virtual: true }); | ||
|
||
expect(() => require('../setupJest')).toThrow('core-js es6-reflect not found!'); | ||
}); | ||
|
||
it('should import from core-js@2', () => { | ||
jest.mock('core-js/es6/reflect', () => true, { virtual: true }); | ||
jest.mock('core-js/es/reflect', () => { throw coreJs3Error }, { virtual: true }); | ||
|
||
expect(() => require('../setupJest')).not.toThrow(); | ||
}); | ||
|
||
it('should import from core-js@3', () => { | ||
jest.mock('core-js/es6/reflect', () => { throw coreJs2Error }, { virtual: true }); | ||
jest.mock('core-js/es/reflect', () => true, { virtual: true }); | ||
|
||
expect(() => require('../setupJest')).not.toThrow(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
describe('importing ES7 reflect', () => { | ||
|
||
let setMocks = () => { | ||
jest.mock('@angular/core/testing', () => ({ getTestBed: () => ({ initTestEnvironment() { } }) }), { virtual: true }) | ||
jest.mock('@angular/platform-browser-dynamic/testing', () => ({ BrowserDynamicTestingModule: null, platformBrowserDynamicTesting: () => { } }), { virtual: true }) | ||
jest.mock('zone.js/dist/zone.js', () => true, { virtual: true }); | ||
jest.mock('zone.js/dist/proxy.js', () => true, { virtual: true }); | ||
jest.mock('zone.js/dist/sync-test', () => true, { virtual: true }); | ||
jest.mock('zone.js/dist/async-test', () => true, { virtual: true }); | ||
jest.mock('zone.js/dist/fake-async-test', () => true, { virtual: true }); | ||
jest.mock('../zone-patch', () => true, { virtual: true }); | ||
|
||
jest.mock('core-js/es6/reflect', () => true, { virtual: true }); | ||
jest.mock('core-js/es/reflect', () => true, { virtual: true }); | ||
} | ||
|
||
let coreJs2Error = new Error('core-js@2 es7 reflect failed'); | ||
let coreJs3Error = new Error('core-js@3 es7 reflect failed'); | ||
|
||
beforeEach(() => setMocks()); | ||
afterEach(() => jest.resetAllMocks()); | ||
|
||
it('should throw if core-js es7-reflect is not installed', () => { | ||
jest.mock('core-js/es7/reflect', () => { throw coreJs2Error }, { virtual: true }); | ||
jest.mock('core-js/proposals/reflect-metadata', () => { throw coreJs3Error }, { virtual: true }); | ||
|
||
expect(() => require('../setupJest')).toThrow('core-js es7-reflect not found!'); | ||
}); | ||
|
||
it('should import from core-js@2', () => { | ||
jest.mock('core-js/es7/reflect', () => true, { virtual: true }); | ||
jest.mock('core-js/proposals/reflect-metadata', () => { throw coreJs3Error }, { virtual: true }); | ||
|
||
expect(() => require('../setupJest')).not.toThrow(); | ||
}); | ||
|
||
it('should import from core-js@3', () => { | ||
jest.mock('core-js/es7/reflect', () => { throw coreJs2Error }, { virtual: true }); | ||
jest.mock('core-js/proposals/reflect-metadata', () => true, { virtual: true }); | ||
|
||
expect(() => require('../setupJest')).not.toThrow(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ | |
"target": "es5", | ||
"baseUrl": "", | ||
"allowJs": true, | ||
"types": ["jest"] | ||
"types": ["jest", "node"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,37 @@ | ||
'use strict'; | ||
'use strict'; | ||
|
||
require('core-js/es6/reflect'); | ||
require('core-js/es7/reflect'); | ||
require('zone.js/dist/zone.js'); | ||
require('zone.js/dist/proxy.js'); | ||
require('zone.js/dist/sync-test'); | ||
require('zone.js/dist/async-test'); | ||
require('zone.js/dist/fake-async-test'); | ||
try { | ||
require('core-js/es6/reflect'); | ||
} catch (e) { | ||
try { | ||
require('core-js/es/reflect'); | ||
} catch(e) { | ||
throw new Error('core-js es6-reflect not found!'); | ||
} | ||
} | ||
|
||
try { | ||
require('core-js/es7/reflect'); | ||
} catch (e) { | ||
try { | ||
require('core-js/proposals/reflect-metadata'); | ||
} catch (e) { | ||
throw new Error('core-js es7-reflect not found!'); | ||
} | ||
} | ||
|
||
require('zone.js/dist/zone.js'); | ||
require('zone.js/dist/proxy.js'); | ||
require('zone.js/dist/sync-test'); | ||
require('zone.js/dist/async-test'); | ||
require('zone.js/dist/fake-async-test'); | ||
require('./zone-patch'); | ||
|
||
const getTestBed = require('@angular/core/testing').getTestBed; | ||
const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule; | ||
const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing').platformBrowserDynamicTesting; | ||
const getTestBed = require('@angular/core/testing').getTestBed; | ||
const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule; | ||
const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing').platformBrowserDynamicTesting; | ||
|
||
getTestBed().initTestEnvironment( | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting() | ||
getTestBed().initTestEnvironment( | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting() | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters