-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): support ESM for
isolatedModules: false
(#721)
- Make sure `esModuleInterop` and `allowSyntheticDefaultImports` true to support import CJS into ESM - Adjust `module` value correctly according to Jest transform option `supportsStaticESM` and `ts-jest` config `useESM`
- Loading branch information
Showing
11 changed files
with
160 additions
and
31 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,20 @@ | ||
require('jest-preset-angular/ngcc-jest-processor'); | ||
const baseConfig = require('./jest.config'); | ||
|
||
/** @type {import('ts-jest/dist/types').ProjectConfigTsJest} */ | ||
module.exports = { | ||
...baseConfig, | ||
extensionsToTreatAsEsm: ['.ts'], | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig-esm.spec.json', | ||
stringifyContentPathRegex: '\\.html$', | ||
useESM: true, | ||
} | ||
}, | ||
moduleNameMapper: { | ||
...baseConfig.moduleNameMapper, | ||
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js', | ||
}, | ||
transformIgnorePatterns: ['node_modules/(?!tslib)'], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require('jest-preset-angular/ngcc-jest-processor'); | ||
const baseConfig = require('./jest.config'); | ||
|
||
/** @type {import('ts-jest/dist/types').ProjectConfigTsJest} */ | ||
module.exports = { | ||
...baseConfig, | ||
extensionsToTreatAsEsm: ['.ts'], | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig-esm.spec.json', | ||
stringifyContentPathRegex: '\\.html$', | ||
useESM: true, | ||
} | ||
}, | ||
moduleNameMapper: { | ||
...baseConfig.moduleNameMapper, | ||
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js', | ||
}, | ||
transformIgnorePatterns: ['node_modules/(?!tslib)'], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require('jest-preset-angular/ngcc-jest-processor'); | ||
const baseConfig = require('./jest.config'); | ||
|
||
/** @type {import('ts-jest/dist/types').ProjectConfigTsJest} */ | ||
module.exports = { | ||
...baseConfig, | ||
extensionsToTreatAsEsm: ['.ts'], | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig-esm.spec.json', | ||
stringifyContentPathRegex: '\\.html$', | ||
useESM: true, | ||
} | ||
}, | ||
moduleNameMapper: { | ||
...baseConfig.moduleNameMapper, | ||
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js', | ||
}, | ||
transformIgnorePatterns: ['node_modules/(?!tslib)'], | ||
}; |
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,5 +1,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NgJestCompiler with isolatedModule false should compile codes with useESM true 1`] = ` | ||
"import { __decorate } from \\"tslib\\"; | ||
import __NG_CLI_RESOURCE__0 from \\"./app.component.html\\"; | ||
import { Component } from '@angular/core'; | ||
let AppComponent = class AppComponent { | ||
constructor() { | ||
this.title = 'test-app-v10'; | ||
} | ||
}; | ||
AppComponent = __decorate([ | ||
Component({ | ||
selector: 'app-root', | ||
template: __NG_CLI_RESOURCE__0, | ||
styles: [] | ||
}) | ||
], AppComponent); | ||
export { AppComponent }; | ||
//# " | ||
`; | ||
|
||
exports[`NgJestCompiler with isolatedModule false should throw diagnostics error for new file which is: known by Program 1`] = `"src/__tests__/__mocks__/foo.component.ts(8,3): error TS2322: Type '\\"test-app-v10\\"' is not assignable to type 'number'."`; | ||
|
||
exports[`NgJestCompiler with isolatedModule false should throw diagnostics error for new file which is: not known by Program 1`] = `"src/__tests__/__mocks__/foo.component.ts(8,3): error TS2322: Type '\\"test-app-v10\\"' is not assignable to type 'number'."`; |
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