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

perf: process js files in node_modules with esbuild #1169

Merged
merged 1 commit into from
Nov 15, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ e2e/**/.yarn/*
!e2e/**/.yarn/sdks
!e2e/**/.yarn/versions
!/e2e/ng-lib-import/node_modules
!/e2e/process-js-packages/node_modules
src/transformers/downlevel_decorators_transform
src/ngtsc
10 changes: 5 additions & 5 deletions e2e/__tests__/ast-transformers.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { json as runWithJson } from '../run-jest';
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';

describe('hoisting', () => {
const DIR = 'ast-transformers/hoisting';

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
Expand All @@ -20,13 +20,13 @@ describe('ng-jit-transformers', () => {
const DIR = 'ast-transformers/ng-jit-transformers';

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
Expand Down
6 changes: 3 additions & 3 deletions e2e/__tests__/async.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { json as runWithJson } from '../run-jest';
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
import { runYarnInstall } from '../utils';

const DIR = path.join(__dirname, '..', 'async');
Expand All @@ -10,13 +10,13 @@ beforeAll(() => {
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
6 changes: 3 additions & 3 deletions e2e/__tests__/babel-support.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { json as runWithJson } from '../run-jest';
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
import { runYarnInstall } from '../utils';

const DIR = path.join(__dirname, '..', 'babel-support');
Expand All @@ -10,13 +10,13 @@ beforeAll(() => {
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
6 changes: 3 additions & 3 deletions e2e/__tests__/custom-typings.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { json as runWithJson } from '../run-jest';
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
import { runYarnInstall } from '../utils';

const DIR = path.join(__dirname, '..', 'custom-typings');
Expand All @@ -10,13 +10,13 @@ beforeAll(() => {
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
6 changes: 3 additions & 3 deletions e2e/__tests__/jest-globals.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { json as runWithJson } from '../run-jest';
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';

const DIR = 'jest-globals';

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
6 changes: 3 additions & 3 deletions e2e/__tests__/ng-deep-import.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { json as runWithJson } from '../run-jest';
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';

const DIR = 'ng-deep-import';

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
6 changes: 3 additions & 3 deletions e2e/__tests__/ng-lib-import.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { json as runWithJson } from '../run-jest';
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';

const DIR = 'ng-lib-import';

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
6 changes: 3 additions & 3 deletions e2e/__tests__/path-mapping.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { json as runWithJson } from '../run-jest';
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';

const DIR = 'path-mapping';

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
27 changes: 27 additions & 0 deletions e2e/__tests__/process-js-packages.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import fs from 'fs';
import path from 'path';

import { jsonNoCache as runWithJsonNoCache } from '../run-jest';

const TEST_DIR_NAME = 'process-js-packages';
const TEST_DIR_PATH = path.join(__dirname, '..', TEST_DIR_NAME);
const LOG_FILE_NAME = 'ng-jest.log';
const LOG_FILE_PATH = path.join(TEST_DIR_PATH, LOG_FILE_NAME);

test(`successfully runs the tests inside ${TEST_DIR_NAME}`, () => {
process.env.NG_JEST_LOG = LOG_FILE_NAME;

const { json } = runWithJsonNoCache(TEST_DIR_NAME);

expect(json.success).toBe(true);
expect(fs.existsSync(LOG_FILE_PATH)).toBe(true);

const logFileContent = fs.readFileSync(LOG_FILE_PATH, 'utf-8');
const logFileContentAsJson = JSON.parse(logFileContent);

expect(/node_modules\/(.*.m?js$)/.test(logFileContentAsJson.context.filePath.replace(/\\/g, '/'))).toBe(true);
expect(logFileContentAsJson.message).toBe('process with esbuild');

delete process.env.NG_JEST_LOG;
fs.unlinkSync(LOG_FILE_PATH);
});
6 changes: 3 additions & 3 deletions e2e/__tests__/snapshot-serializers.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { json as runWithJson } from '../run-jest';
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';

const DIR = 'snapshot-serializers';

test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJson(DIR);
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
});

test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
});
5 changes: 5 additions & 0 deletions e2e/process-js-packages/__tests__/foo-js-packages.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { foo } from 'my-lib';

test('should pass', () => {
expect(foo).toBe(1);
});
1 change: 1 addition & 0 deletions e2e/process-js-packages/node_modules/my-lib/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions e2e/process-js-packages/node_modules/my-lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions e2e/process-js-packages/node_modules/my-lib/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions e2e/process-js-packages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "process-js-packages",
"jest": {
"moduleFileExtensions": ["ts", "html", "js", "json", "mjs"],
"globals": {
"ts-jest": {
"isolatedModules": true
}
},
"transform": {
"^.+\\.(ts|js|mjs|html)$": "<rootDir>/../../build/index.js"
},
"transformIgnorePatterns": ["node_modules/(?!my-lib)"]
}
}
4 changes: 4 additions & 0 deletions e2e/run-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export const json = function (dir: string, args?: string[], options: RunJestOpti
}
};

export const jsonNoCache = (dir: string, args?: string[], options: RunJestOptions = {}): RunJestJsonResult => {
return json(dir, args ? [...args, '--no-cache'] : ['--no-cache'], options);
};

export const onNodeVersions = (versionRange: string, testBody: () => void): void => {
const description = `on node ${versionRange}`;
if (semver.satisfies(process.versions.node, versionRange)) {
Expand Down
9 changes: 9 additions & 0 deletions scripts/test-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { exampleAppsToRun, rootDir } = require('./paths');
const executeTest = (projectPath) => {
// we change current directory
process.chdir(projectPath);

// reading package.json
const projectPkg = require(join(projectPath, 'package.json'));
if (!projectPkg.name) projectPkg.name = 'unknown';
Expand All @@ -19,6 +20,11 @@ const executeTest = (projectPath) => {
logger.log('='.repeat(20), `${projectPkg.name}@${projectPkg.version}`, 'in', projectPath, '='.repeat(20));
logger.log();

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

execa.sync('rimraf', [join(projectPath, 'node_modules')]);

// then we install it in the repo
logger.log('ensuring all dependencies of target project are installed');
logger.log();
Expand Down Expand Up @@ -50,6 +56,7 @@ const executeTest = (projectPath) => {
env: process.env,
});

logger.log();
logger.log('starting the CommonJS tests with isolatedModules: true using:', ...cmdIsolatedLine);
logger.log();

Expand All @@ -61,6 +68,7 @@ const executeTest = (projectPath) => {

// TODO: Enable when fully support ESM with Angular 13
if (!projectPkg.version.startsWith('13')) {
logger.log();
logger.log('starting the ESM tests with isolatedModules: false using:', ...cmdESMLine);
logger.log();

Expand All @@ -70,6 +78,7 @@ const executeTest = (projectPath) => {
env: process.env,
});

logger.log();
logger.log('starting the ESM tests with isolatedModules: true using:', ...cmdESMIsolatedLine);
logger.log();

Expand Down
Loading