From 5754f236905df803151d5dac7cadc07a655f6ab1 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Sat, 2 Sep 2023 20:19:53 +0100 Subject: [PATCH 1/3] Dev: ESLint run on largest files first [fix] --- jest-eslint.config.js | 1 + test/support/eslintSequencer.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/support/eslintSequencer.js diff --git a/jest-eslint.config.js b/jest-eslint.config.js index b5d4fed5..1f3c140a 100644 --- a/jest-eslint.config.js +++ b/jest-eslint.config.js @@ -10,6 +10,7 @@ module.exports = { testEnvironment: 'node', runner: 'jest-runner-eslint', + testSequencer: '/test/support/eslintSequencer.js', testMatch: ['/**/*.(js|cjs|mjs|jsx)'], // Jest by default uses a number of workers equal to number of CPU cores minus 1. // Github Actions runners provide 2 cores and running with 2 workers is faster than 1. diff --git a/test/support/eslintSequencer.js b/test/support/eslintSequencer.js new file mode 100644 index 00000000..49b484d4 --- /dev/null +++ b/test/support/eslintSequencer.js @@ -0,0 +1,26 @@ +/* -------------------- + * livepack + * Custom test sequencer for Jest ESLint + * ------------------*/ + +'use strict'; + +// Modules +const fs = require('fs'), + Sequencer = require('@jest/test-sequencer').default; + +// Exports + +// Custom sequencer to ensure the largest files are run first. +// `jest-runner-eslint` doesn't seem to sequence automatically. +// https://github.com/jest-community/jest-runner-eslint/issues/204 +// TODO: Remove this workaround once above issue is fixed. + +module.exports = class CustomSequencer extends Sequencer { + sort(tests) { + tests = super.sort(tests); + const testsWithFileSizes = tests.map(test => ({test, size: fs.statSync(test.path).size})); + testsWithFileSizes.sort((t1, t2) => (t1.size > t2.size ? -1 : t1.size < t2.size ? 1 : 0)); + return testsWithFileSizes.map(({test}) => test); + } +}; From b83e7ee498a34152a9844e419db8e996fe0a07a0 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Sun, 3 Sep 2023 01:47:29 +0100 Subject: [PATCH 2/3] Tests: Avoid instrumenting modules used by testing infrastructure [fix] Fixes #474. --- jest.config.js | 2 ++ test/support/register.js | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/jest.config.js b/jest.config.js index c06593a1..fb0ecd13 100644 --- a/jest.config.js +++ b/jest.config.js @@ -26,6 +26,8 @@ module.exports = { '/test/support/register.js' ], testSequencer: '/test/support/sequencer.js', + // Disable babel-jest transformation + transform: {}, // Jest by default uses a number of workers equal to number of CPU cores minus 1. // Github Actions runners provide 2 cores and running with 2 workers is faster than 1. ...(process.env.CI && {maxWorkers: '100%'}) diff --git a/test/support/register.js b/test/support/register.js index a27c94ee..43443126 100644 --- a/test/support/register.js +++ b/test/support/register.js @@ -3,22 +3,39 @@ * Tests install require hook to intrument test files' code * ------------------*/ -/* eslint-disable import/order, import/newline-after-import */ +/* eslint-disable import/order, import/no-dynamic-require, global-require */ 'use strict'; +// Imports +const { + useInternalModuleCache, useGlobalModuleCache, usingInternalModuleCache, Module +} = require('../../lib/shared/moduleCache.js'); + // Patch filesystem for virtual fixtures files require('./fixturesFs.js'); +// Pre-load `fast-json-stable-stringify`. +// `jest-light-runner` imports `jest-snapshot` which requires `@jest/transform`. +// After `jest-light-runner`'s worker loads the test file, it runs a method on `jest-snapshot` +// which causes `@jest/transform` to lazily require `fast-json-stable-stringify`. +// Trigger this now, so `fast-json-stable-stringify` is not loaded later and unnecessarily instrumented. +// `createScriptTransformer()` when called with no arguments throws an error before it does anything. +const {createRequire} = Module, + jestLightRunnerPath = require.resolve('jest-light-runner'), + jestSnapshotPath = createRequire(jestLightRunnerPath).resolve('jest-snapshot'), + jestTransformPath = createRequire(jestSnapshotPath).resolve('@jest/transform'); +if (Module._cache[jestTransformPath]) { + const jestTransform = require(jestTransformPath); + jestTransform.createScriptTransformer().catch(() => {}); +} + // Install register require hook. // Disable instrumentation cache. Tests run in multiple threads, so it'd be read from and written to // concurrently unless disabled. require('../../register.js')({cache: false}); // Use internal module cache to avoid transpiling modules -const { - useInternalModuleCache, useGlobalModuleCache, usingInternalModuleCache -} = require('../../lib/shared/moduleCache.js'); useInternalModuleCache(); // Modules From 32eb635167da8041baad1e3ac1bee5a8f31eb6ed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 16:33:27 +0000 Subject: [PATCH 3/3] Deps: Bump @babel/generator from 7.22.10 to 7.22.15 Bumps [@babel/generator](https://github.com/babel/babel/tree/HEAD/packages/babel-generator) from 7.22.10 to 7.22.15. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.22.15/packages/babel-generator) --- updated-dependencies: - dependency-name: "@babel/generator" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 24 ++++++++++++------------ package.json | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 54c1d255..0f83fcd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@babel/core": "^7.22.11", - "@babel/generator": "^7.22.10", + "@babel/generator": "^7.22.15", "@babel/helper-module-transforms": "^7.22.9", "@babel/parser": "^7.22.13", "@babel/plugin-transform-modules-commonjs": "^7.22.11", @@ -144,11 +144,11 @@ "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==" }, "node_modules/@babel/generator": { - "version": "7.22.10", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.22.10.tgz", - "integrity": "sha512-79KIf7YiWjjdZ81JnLujDRApWtl7BxTqWD88+FFdQEIOG8LJ0etDOM7CXuIgGJa55sGOwZVwuEsaLEm0PJ5/+A==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.22.15.tgz", + "integrity": "sha512-Zu9oWARBqeVOW0dZOjXc3JObrzuqothQ3y/n1kUtrjCoCPLkXUwMvOo/F/TCfoHMbWIFlWwpZtkZVb9ga4U2pA==", "dependencies": { - "@babel/types": "^7.22.10", + "@babel/types": "^7.22.15", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -282,9 +282,9 @@ } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz", - "integrity": "sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.15.tgz", + "integrity": "sha512-4E/F9IIEi8WR94324mbDUMo074YTheJmd7eZF5vITTeYchqAi6sYXRLHUVsmkdmY4QjfKTcB2jB7dVP3NaBElQ==", "engines": { "node": ">=6.9.0" } @@ -619,12 +619,12 @@ } }, "node_modules/@babel/types": { - "version": "7.22.11", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.11.tgz", - "integrity": "sha512-siazHiGuZRz9aB9NpHy9GOs9xiQPKnMzgdr493iI1M67vRXpnEq8ZOOKzezC5q7zwuQ6sDhdSp4SD9ixKSqKZg==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.15.tgz", + "integrity": "sha512-X+NLXr0N8XXmN5ZsaQdm9U2SSC3UbIYq/doL++sueHOTisgZHoKaQtZxGuV2cUPQHMfjKEfg/g6oy7Hm6SKFtA==", "dependencies": { "@babel/helper-string-parser": "^7.22.5", - "@babel/helper-validator-identifier": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.15", "to-fast-properties": "^2.0.0" }, "engines": { diff --git a/package.json b/package.json index 0afc7883..7b0c1f08 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "@babel/core": "^7.22.11", - "@babel/generator": "^7.22.10", + "@babel/generator": "^7.22.15", "@babel/helper-module-transforms": "^7.22.9", "@babel/parser": "^7.22.13", "@babel/plugin-transform-modules-commonjs": "^7.22.11",