Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): use replace-resources transformer from Angular for isolatedModules: true #717

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/__tests__/__snapshots__/hoisting.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Hoisting should hoist correctly 1`] = `
exports[`Hoisting should hoist correctly with isolatedModules false 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", { value: true });
const globals_1 = require(\\"@jest/globals\\");
globals_1.jest.mock('./foo');
const foo_1 = require(\\"./foo\\");
console.log(foo_1.getFoo());
//# "
`;

exports[`Hoisting should hoist correctly with isolatedModules true 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", { value: true });
const globals_1 = require(\\"@jest/globals\\");
Expand Down
207 changes: 0 additions & 207 deletions src/__tests__/__snapshots__/inline-files.spec.ts.snap

This file was deleted.

51 changes: 46 additions & 5 deletions src/__tests__/__snapshots__/replace-resources.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Replace resources transformer should use inline-files + strip-styles for isolatedModules true 1`] = `
exports[`Replace resources transformer with isolatedModules false should use replaceResources transformer from @angular/compiler-cli with useESM false 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", { value: true });
exports.AppComponent = void 0;
Expand All @@ -14,16 +14,15 @@ let AppComponent = class AppComponent {
AppComponent = tslib_1.__decorate([
core_1.Component({
selector: 'app-root',
template: require('./app.component.html'),
styleUrls: [],
styles: [],
template: require(\\"./app.component.html\\"),
styles: []
})
], AppComponent);
exports.AppComponent = AppComponent;
//# "
`;

exports[`Replace resources transformer should use replaceResources transformer from @angular/compiler-cli for isolatedModules false 1`] = `
exports[`Replace resources transformer with isolatedModules false should use replaceResources transformer from @angular/compiler-cli with useESM true 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", { value: true });
exports.AppComponent = void 0;
Expand All @@ -44,3 +43,45 @@ AppComponent = tslib_1.__decorate([
exports.AppComponent = AppComponent;
//# "
`;

exports[`Replace resources transformer with isolatedModules true should use replaceResources transformer from @angular/compiler-cli with useESM false 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", { value: true });
exports.AppComponent = void 0;
const tslib_1 = require(\\"tslib\\");
const core_1 = require(\\"@angular/core\\");
let AppComponent = class AppComponent {
constructor() {
this.title = 'test-app-v10';
}
};
AppComponent = tslib_1.__decorate([
core_1.Component({
selector: 'app-root',
template: require(\\"./app.component.html\\"),
styles: []
})
], AppComponent);
exports.AppComponent = AppComponent;
//# "
`;

exports[`Replace resources transformer with isolatedModules true should use replaceResources transformer from @angular/compiler-cli 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 };
//# "
`;
47 changes: 0 additions & 47 deletions src/__tests__/__snapshots__/strip-styles.spec.ts.snap

This file was deleted.

12 changes: 10 additions & 2 deletions src/__tests__/hoisting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ import { mockFolder } from './__helpers__/test-helpers';

describe('Hoisting', () => {
// Verify if we use `ts-jest` hoisting transformer
test('should hoist correctly', () => {
const ngJestConfig = new NgJestConfig(jestCfgStub);
test.each([true, false])('should hoist correctly with isolatedModules %p', (isolatedModules) => {
const ngJestConfig = new NgJestConfig({
...jestCfgStub,
globals: {
'ts-jest': {
...jestCfgStub.globals['ts-jest'],
isolatedModules,
},
},
});
const fileName = join(mockFolder, 'foo.spec.ts');
const compiler = new NgJestCompiler(ngJestConfig, new Map());

Expand Down
Loading