Skip to content

Commit

Permalink
Fix ts-node scripts on Node 20 (#1564)
Browse files Browse the repository at this point in the history
* Fix ts-node scripts on Node 20

* Adapt exception assertion for Node 20
  • Loading branch information
ovidiuch committed Nov 19, 2023
1 parent dd79b2c commit 2dc6672
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
node-version: '20'
cache: 'yarn'
- run: yarn install --frozen-lockfile --network-timeout 600000

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-pnp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: '18'
node-version: '20'
cache: 'yarn'
cache-dependency-path: |
react-cosmos/yarn.lock
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
node-version: '20'
cache: 'yarn'
- run: yarn install --frozen-lockfile --network-timeout 600000

Expand All @@ -38,24 +38,24 @@ jobs:
matrix:
example: [webpack, vite]
os: [ubuntu, windows]
node-version: [18]
node-version: [20]
lazy: [false]
include:
- example: webpack
os: ubuntu
node-version: 16
node-version: 18
lazy: false
- example: webpack
os: windows
node-version: 16
node-version: 18
lazy: false
- example: webpack
os: ubuntu
node-version: 18
node-version: 20
lazy: true
- example: vite
os: ubuntu
node-version: 18
node-version: 20
lazy: true
runs-on: ${{ matrix.os }}-latest
steps:
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"test:watch": "yarn test:unit --watch",
"test:coverage": "yarn test:unit --coverage",
"test:cypress": "cypress run --config-file cypress/cypress.config.ts --record false",
"link-entries": "ts-node --esm ./scripts/linkEntries.ts",
"link-entries": "node --loader ts-node/esm ./scripts/linkEntries.ts",
"src": "yarn link-entries src",
"dist": "yarn link-entries dist",
"build:clear": "ts-node --esm ./scripts/clearBuild.ts",
"build": "ts-node --esm ./scripts/build.ts",
"demo:build": "ts-node --esm ./scripts/buildDemo.ts",
"website:build": "ts-node --esm ./scripts/buildWebsite.ts",
"build:clear": "node --loader ts-node/esm ./scripts/clearBuild.ts",
"build": "node --loader ts-node/esm ./scripts/build.ts",
"demo:build": "node --loader ts-node/esm ./scripts/buildDemo.ts",
"website:build": "node --loader ts-node/esm ./scripts/buildWebsite.ts",
"website:serve": "http-server -p 5001 ./website/dist",
"release:check": "yarn build:clear && yarn build && yarn src && yarn lint && yarn dist && yarn test:unit",
"release": "yarn release:check && yarn lerna publish -m \"[skip ci] %s\"",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Import mocks first
import { jestWorkerId } from '../../testHelpers/jestWorkerId.js';
import { jestWorkerId } from '../../testHelpers/jestProcessUtils.js';
import { mockConsole } from '../../testHelpers/mockConsole.js';
import { mockCosmosPlugins } from '../../testHelpers/mockCosmosPlugins.js';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Import mocks first
import { jestWorkerId } from '../../testHelpers/jestWorkerId.js';
import { jestWorkerId } from '../../testHelpers/jestProcessUtils.js';
import { mockConsole } from '../../testHelpers/mockConsole.js';
import { mockCosmosPlugins } from '../../testHelpers/mockCosmosPlugins.js';
import { mockCosmosConfig, resetFsMock } from '../../testHelpers/mockFs.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Import mocks first
import { jestWorkerId } from '../../testHelpers/jestWorkerId.js';
import {
jestNodeVersion,
jestWorkerId,
} from '../../testHelpers/jestProcessUtils.js';
import { mockConsole } from '../../testHelpers/mockConsole.js';
import { mockCosmosPlugins } from '../../testHelpers/mockCosmosPlugins.js';
import { mockCosmosConfig, resetFsMock } from '../../testHelpers/mockFs.js';
Expand Down Expand Up @@ -152,7 +155,9 @@ it('stops server', async () => {
await stopServer();

await expect(fetch(`http://localhost:${port}`)).rejects.toThrow(
'ECONNREFUSED'
jestNodeVersion() >= 20
? `request to http://localhost:${port}/ failed`
: 'ECONNREFUSED'
);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Import mocks first
import { jestWorkerId } from '../../testHelpers/jestWorkerId.js';
import { jestWorkerId } from '../../testHelpers/jestProcessUtils.js';
import { mockConsole } from '../../testHelpers/mockConsole.js';
import { mockCosmosPlugins } from '../../testHelpers/mockCosmosPlugins.js';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Import mocks first
import { jestWorkerId } from '../../testHelpers/jestWorkerId.js';
import { jestWorkerId } from '../../testHelpers/jestProcessUtils.js';
import { mockConsole } from '../../testHelpers/mockConsole.js';
import { mockCosmosPlugins } from '../../testHelpers/mockCosmosPlugins.js';
import { mockCosmosConfig, resetFsMock } from '../../testHelpers/mockFs.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Import mocks first
import { jestWorkerId } from '../../testHelpers/jestWorkerId.js';
import { jestWorkerId } from '../../testHelpers/jestProcessUtils.js';
import { mockConsole } from '../../testHelpers/mockConsole.js';
import { mockCosmosPlugins } from '../../testHelpers/mockCosmosPlugins.js';
import { mockCosmosConfig, resetFsMock } from '../../testHelpers/mockFs.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function jestWorkerId() {
return parseInt(process.env.JEST_WORKER_ID || '1', 10);
}

export function jestNodeVersion() {
return parseInt(process.versions.node);
}

0 comments on commit 2dc6672

Please sign in to comment.