Skip to content

Commit

Permalink
test(e2e): run e2e tests with ESM and isolatedModules: true (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl authored Jan 8, 2021
1 parent cdaab7e commit 5888706
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 35 deletions.
3 changes: 2 additions & 1 deletion e2e/__tests__/calc/calc.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Input } from '@angular/core';
import * as image from 'e2e/test-app-v10/src/assets/its_something.png';

import image from './its_something.png';

@Component({
selector: 'app-calc',
Expand Down
Binary file added e2e/__tests__/calc/its_something.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions e2e/__tests__/forward-ref/forward-ref.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { forwardRef, Inject, Injector } from '@angular/core';

const shouldSkipTest = process.env.NG_VERSION === 'v9' || process.env.ISOLATED_MODULES === 'true';
const shouldSkipTest = process.env.ISOLATED_MODULES === 'true';
const skipTest = shouldSkipTest ? test.skip : test;

if (shouldSkipTest) {
process.stdout.write(
'\nforwardRef only works in non-isolatedModules mode with ES2015 in Angular 10+, with Angular 9 requires ES5\n',
);
process.stdout.write('\nforwardRef only works in non-isolatedModules mode\n');
}

skipTest('forwardRef should work', () => {
Expand Down
1 change: 1 addition & 0 deletions e2e/__tests__/heroes/hero.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpClientModule, HttpErrorResponse, HttpRequest } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { inject, TestBed } from '@angular/core/testing';
import { jest } from '@jest/globals';

import { heroesUrl, HeroService } from './hero.service';

Expand Down
1 change: 1 addition & 0 deletions e2e/__tests__/heroes/heroes.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { async, ComponentFixture } from '@angular/core/testing';
import { jest } from '@jest/globals';
import { Subject } from 'rxjs';

import { ConfigureFn, configureTests } from '../__helpers__';
Expand Down
6 changes: 6 additions & 0 deletions e2e/test-app-v10/jest-esm-iso.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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',
Expand All @@ -12,4 +13,9 @@ module.exports = {
isolatedModules: true,
}
},
moduleNameMapper: {
...baseConfig.moduleNameMapper,
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js',
},
transformIgnorePatterns: ['node_modules/(?!tslib)'],
};
5 changes: 3 additions & 2 deletions e2e/test-app-v10/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test-cjs-uniso": "jest --clearCache && jest -c=jest-cjs-uniso.config.js -u",
"test-cjs-uniso": "jest --clearCache && jest -c=jest-cjs-uniso.config.js",
"test-cjs-iso": "jest --clearCache && jest -c=jest-cjs-iso.config.js",
"test-esm-iso": "jest --clearCache && node --experimental-vm-modules ./node_modules/jest/bin/jest.js -c=jest-esm-iso.config.js",
"lint": "ng lint"
},
"private": true,
Expand Down Expand Up @@ -37,4 +38,4 @@
"ts-node": "^9.1.1",
"typescript": "~4.0.5"
}
}
}
3 changes: 1 addition & 2 deletions e2e/test-app-v10/tsconfig-esm.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
"extends": "./tsconfig.spec.json",
"compilerOptions": {
"module": "ESNext",
"esModuleInterop": true
"module": "ESNext"
},
}
4 changes: 3 additions & 1 deletion e2e/test-app-v10/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"jquery",
"node"
],
"allowJs": true
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"files": [
"src/global.ts"
Expand Down
6 changes: 6 additions & 0 deletions e2e/test-app-v11/jest-esm-iso.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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',
Expand All @@ -12,4 +13,9 @@ module.exports = {
isolatedModules: true,
}
},
moduleNameMapper: {
...baseConfig.moduleNameMapper,
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js',
},
transformIgnorePatterns: ['node_modules/(?!tslib)'],
};
3 changes: 2 additions & 1 deletion e2e/test-app-v11/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "ng build",
"test-cjs-uniso": "jest --clearCache && jest -c=jest-cjs-uniso.config.js",
"test-cjs-iso": "jest --clearCache && jest -c=jest-cjs-iso.config.js",
"test-esm-iso": "jest --clearCache && node --experimental-vm-modules ./node_modules/jest/bin/jest.js -c=jest-esm-iso.config.js",
"lint": "ng lint"
},
"private": true,
Expand Down Expand Up @@ -37,4 +38,4 @@
"ts-node": "^9.1.1",
"typescript": "~4.0.5"
}
}
}
3 changes: 1 addition & 2 deletions e2e/test-app-v11/tsconfig-esm.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
"extends": "./tsconfig.spec.json",
"compilerOptions": {
"module": "ESNext",
"esModuleInterop": true
"module": "ESNext"
},
}
4 changes: 3 additions & 1 deletion e2e/test-app-v11/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"jquery",
"node"
],
"allowJs": true
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"files": [
"src/global.ts"
Expand Down
6 changes: 6 additions & 0 deletions e2e/test-app-v9/jest-esm-iso.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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',
Expand All @@ -12,4 +13,9 @@ module.exports = {
isolatedModules: true,
}
},
moduleNameMapper: {
...baseConfig.moduleNameMapper,
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js',
},
transformIgnorePatterns: ['node_modules/(?!tslib)'],
};
3 changes: 2 additions & 1 deletion e2e/test-app-v9/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "ng build",
"test-cjs-uniso": "jest --clearCache && jest -c=jest-cjs-uniso.config.js",
"test-cjs-iso": "jest --clearCache && jest -c=jest-cjs-iso.config.js",
"test-esm-iso": "jest --clearCache && node --experimental-vm-modules ./node_modules/jest/bin/jest.js -c=jest-esm-iso.config.js",
"lint": "ng lint"
},
"private": true,
Expand Down Expand Up @@ -37,4 +38,4 @@
"ts-node": "^9.1.1",
"typescript": "~3.8.3"
}
}
}
3 changes: 1 addition & 2 deletions e2e/test-app-v9/tsconfig-esm.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
"extends": "./tsconfig.spec.json",
"compilerOptions": {
"module": "ESNext",
"esModuleInterop": true
"module": "ESNext"
},
}
4 changes: 3 additions & 1 deletion e2e/test-app-v9/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"jquery",
"node"
],
"allowJs": true
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"files": [
"src/global.ts"
Expand Down
30 changes: 13 additions & 17 deletions scripts/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ const executeTest = (projectRealPath) => {
logger.log('='.repeat(20), `${projectPkg.name}@${projectPkg.version}`, 'in', projectRealPath, '='.repeat(20));
logger.log();

logger.log('setting NG_VERSION environment variable');
logger.log();
const projectName = projectRealPath.match(/([^\\/]*)\/*$/)[1];
process.env.NG_VERSION = projectName.substring(projectName.lastIndexOf('-') + 1);

// then we install it in the repo
logger.log('ensuring all dependencies of target project are installed');
logger.log();
Expand Down Expand Up @@ -61,14 +56,14 @@ const executeTest = (projectRealPath) => {
// then we can run the tests
const cmdCjsUnIso = ['yarn', 'test-cjs-uniso'];
const cmdCjsIso = ['yarn', 'test-cjs-iso'];
// const cmdESMIso = ['yarn', 'test-esm-iso'];
const cmdESMIso = ['yarn', 'test-esm-iso'];
if (jestArgs.length) {
cmdCjsUnIso.push('--');
cmdCjsIso.push('--');
// cmdESMIso.push('--');
cmdESMIso.push('--');
cmdCjsUnIso.push(...jestArgs);
cmdCjsIso.push(...jestArgs);
// cmdESMIso.push(...jestArgs);
cmdESMIso.push(...jestArgs);
}

logger.log('STARTING NONE ISOLATED MODULES TESTS');
Expand Down Expand Up @@ -98,19 +93,20 @@ const executeTest = (projectRealPath) => {
env: process.env,
});

// logger.log('starting the ESM tests using:', ...cmdCjsIso);
// logger.log();
//
// execa.sync(cmdESMIso.shift(), cmdESMIso, {
// cwd: projectRealPath,
// stdio: 'inherit',
// env: process.env,
// });
logger.log();
logger.log('starting the ESM tests using:', ...cmdESMIso);
logger.log();

execa.sync(cmdESMIso.shift(), cmdESMIso, {
cwd: projectRealPath,
stdio: 'inherit',
env: process.env,
});

logger.log();
logger.log('cleaning up');

execa.sync('rimraf', [testCasesDest]);
delete process.env.NG_VERSION;
delete process.env.ISOLATED_MODULES;
};

Expand Down

0 comments on commit 5888706

Please sign in to comment.