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

test: fix windows test #312

Closed
wants to merge 21 commits into from
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [windows-latest]
timeout-minutes: 10

steps:
Expand Down Expand Up @@ -41,6 +41,9 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

- name: Get Node.js cache directory
shell: bash
run: echo "NVE_CACHE=$(node -e 'console.log(require("cachedir")("nve"))')" >> $GITHUB_ENV
Expand All @@ -52,7 +55,12 @@ jobs:
key: ${{ runner.os }}-nodejs-${{ hashFiles('tests/utils/node-versions.ts') }}
restore-keys: ${{ runner.os }}-nodejs-

- name: Download Node.js versions
run: node ./dist/cli.js ./tests/download-node-versions.ts

- name: Test
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: pnpm test

- name: Type check
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"build": "pkgroll --target=node12.19 --minify",
"lint": "eslint --cache .",
"type-check": "tsc --noEmit",
"test": "pnpm build && node ./dist/cli.js tests/index.ts",
"test": "node ./dist/cli.js tests/index.ts",
"prepack": "pnpm build && clean-pkg-json"
},
"simple-git-hooks": {
Expand Down
18 changes: 18 additions & 0 deletions tests/download-node-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import getNode from 'get-node';
import { nodeVersions } from './utils/node-versions';

await Promise.all(
nodeVersions.map(async (nodeVersion) => {
console.log('Downloading Node', nodeVersion);
const startTime = Date.now();
const node = await getNode(nodeVersion, {
progress: true,
});
const elapsed = Date.now() - startTime;
console.log('Downloaded', {
nodeVersion,
elapsed,
node,
});
}),
);
49 changes: 40 additions & 9 deletions tests/specs/typescript/tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,30 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
describe('full path', ({ test }) => {
const importPath = './lib/ts-ext-tsx/index.tsx';

test('Load', async () => {
test('Load', async ({ onTestFail }) => {
const nodeProcess = await node.load(importPath);
onTestFail(() => {
console.log(nodeProcess);
});

assertResults(nodeProcess, node.isCJS);
});

test('Import', async () => {
test('Import', async ({ onTestFail }) => {
const nodeProcess = await node.import(importPath);
onTestFail(() => {
console.log(nodeProcess);
});

assertResults(nodeProcess, node.isCJS);
expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}');
});

test('Require', async () => {
test('Require', async ({ onTestFail }) => {
const nodeProcess = await node.require(importPath);
onTestFail(() => {
console.log(nodeProcess);
});

// By "require()"ing an ESM file, it forces it to be compiled in a CJS context
assertResults(nodeProcess, true);
Expand All @@ -54,19 +65,30 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
describe('extensionless', ({ test }) => {
const importPath = './lib/ts-ext-tsx/index';

test('Load', async () => {
test('Load', async ({ onTestFail }) => {
const nodeProcess = await node.load(importPath);
onTestFail(() => {
console.log(nodeProcess);
});

assertResults(nodeProcess, node.isCJS);
});

test('Import', async () => {
test('Import', async ({ onTestFail }) => {
const nodeProcess = await node.import(importPath);
onTestFail(() => {
console.log(nodeProcess);
});

assertResults(nodeProcess, node.isCJS);
expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}');
});

test('Require', async () => {
test('Require', async ({ onTestFail }) => {
const nodeProcess = await node.require(importPath);
onTestFail(() => {
console.log(nodeProcess);
});

// By "require()"ing an ESM file, it forces it to be compiled in a CJS context
assertResults(nodeProcess, true);
Expand All @@ -77,19 +99,28 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
describe('directory', ({ test }) => {
const importPath = './lib/ts-ext-tsx';

test('Load', async () => {
test('Load', async ({ onTestFail }) => {
const nodeProcess = await node.load(importPath);
onTestFail(() => {
console.log(nodeProcess);
});
assertResults(nodeProcess, node.isCJS);
});

test('Import', async () => {
test('Import', async ({ onTestFail }) => {
const nodeProcess = await node.import(importPath);
onTestFail(() => {
console.log(nodeProcess);
});
assertResults(nodeProcess, node.isCJS);
expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}');
});

test('Require', async () => {
test('Require', async ({ onTestFail }) => {
const nodeProcess = await node.require(importPath);
onTestFail(() => {
console.log(nodeProcess);
});

// By "require()"ing an ESM file, it forces it to be compiled in a CJS context
assertResults(nodeProcess, true);
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default testSuite(async ({ describe }, fixturePath: string) => {

const { all } = await tsxProcess;
expect(all).toMatch('"--help"');
}, 5000);
}, 10_000);
});

describe('ignore', ({ test }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/node-versions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const nodeVersions = [
'18',
'20',
...(
(
Expand All @@ -12,6 +11,7 @@ export const nodeVersions = [
'14',
'16',
'17',
'18',
] as const
: [] as const
),
Expand Down
1 change: 1 addition & 0 deletions tests/utils/tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const tsx = (
options.args,
{
env: {
NODE_OPTIONS: '--max_old_space_size=4096',
ESBK_DISABLE_CACHE: '1',
},
nodePath: options.nodePath,
Expand Down
Loading