Skip to content

Commit 6163244

Browse files
author
mkrause
committed
Move integration test to test runner.
1 parent 733798c commit 6163244

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-14
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ on: [push]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
98

109
strategy:
1110
matrix:
1211
node-version:
1312
- 18.x
1413
- 20.x
15-
#- 22.x # Currently segfaults? https://github.com/fortanix/openapi-to-effect/actions/runs/9235995285/job/25411385965
14+
#- 22.x # `tsc` currently segfaults on Node v22. Possibly due to:
15+
# https://github.com/nodejs/node/issues/52797
1616

1717
steps:
1818
- uses: actions/checkout@v4

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"node": "node --import=tsx",
3939
"check:types": "tsc --noEmit && echo 'No type errors found'",
4040
"//test:unit": "node --import=tsx --test --test-reporter=spec \"**/*.test.ts\" # Note: glob requires Node v22",
41-
"test:unit": "find {src,test} -name \"*.test.ts\" -exec node --import=tsx --test --test-reporter=spec {} ';'",
42-
"test:integration": "./tests/integration/run_integration_tests.sh",
43-
"test": "npm run test:integration # && npm run test:unit",
41+
"test:unit": "find src -name \"*.test.ts\" -exec node --import=tsx --test --test-reporter=spec {} ';'",
42+
"test:integration": "find tests/integration -name \"*.test.ts\" -exec node --import=tsx --test --test-reporter=spec {} ';'",
43+
"test": "npm run test:integration && npm run test:unit",
4444
"test-watch": "node --import=tsx --test --test-reporter=spec --watch tests",
4545
"_build": "NODE_ENV=production babel src --extensions=.ts,.tsx --delete-dir-on-start",
4646
"build:cjs": "BABEL_ENV=cjs npm run _build -- --out-dir=dist/cjs --out-file-extension=.cjs",

tests/integration/fixture1.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* Copyright (c) Fortanix, Inc.
2+
*
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
import { promisify } from 'node:util';
9+
import path from 'node:path';
10+
import { fileURLToPath } from 'node:url';
11+
import { exec as execCallback } from 'node:child_process';
12+
13+
import { Schema as S } from '@effect/schema';
14+
15+
import assert from 'node:assert/strict';
16+
import { test, before } from 'node:test';
17+
18+
19+
const exec = promisify(execCallback);
20+
21+
test('fixture1', { timeout: 30_000/*ms*/ }, async (t) => {
22+
const before = async () => {
23+
const cwd = path.dirname(fileURLToPath(import.meta.url));
24+
console.log('Preparing integration test...');
25+
const { stdout, stderr } = await exec(`./run_integration_tests.sh`, { cwd });
26+
};
27+
await before();
28+
29+
const fixture = await import('../project_simulation/generated/fixture1/fixture1.ts');
30+
31+
await t.test('RocheName', async (t) => {
32+
assert.strictEqual(S.decodeSync(fixture.RocheName)('test'), 'test');
33+
assert.throws(() => S.decodeSync(fixture.RocheName)(''), /Expected a string matching/);
34+
});
35+
});

tests/integration/run_integration_tests.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@ set -euo pipefail
44
# Get the path to the current directory (works in both bash and zsh)
55
# https://stackoverflow.com/a/54755784
66
PATH_CURRENT="$(dirname ${BASH_SOURCE[0]:-${(%):-%x}})"
7+
cd $PATH_CURRENT
78

8-
TEST_SPEC_PATH="${PATH_CURRENT}/../fixtures/fixture1_spec.ts";
9-
TEST_API_PATH="${PATH_CURRENT}/../fixtures/fixture1_api.json";
10-
TEST_OUTPUT_PATH="${PATH_CURRENT}/../project_simulation/generated/fixture1";
11-
mkdir -p "${TEST_OUTPUT_PATH}"
12-
npm run generate -- "--spec=${TEST_SPEC_PATH}" "${TEST_API_PATH}" "${TEST_OUTPUT_PATH}";
9+
# Note: do not use `npm run` here, because `npm run` always changes the working directory to that of the project root
10+
generate() {
11+
node --import=tsx -- "../../src/openapiToEffect.ts" gen "$@"
12+
}
1313

14+
TEST_SPEC_PATH="../fixtures/fixture1_spec.ts";
15+
TEST_API_PATH="../fixtures/fixture1_api.json";
16+
TEST_OUTPUT_PATH="../project_simulation/generated/fixture1";
17+
mkdir -p "${TEST_OUTPUT_PATH}"
18+
generate --spec="${TEST_SPEC_PATH}" "${TEST_API_PATH}" "${TEST_OUTPUT_PATH}"
1419

1520
echo
1621
echo 'Generating sample file...'
17-
cat <<"EOT" | npm run --silent node | prettier --parser=babel-ts --single-quote > "${TEST_OUTPUT_PATH}/fixture1_sample.ts"
22+
cat <<"EOT" | node --import=tsx | npx --silent prettier --parser=babel-ts --single-quote > "${TEST_OUTPUT_PATH}/fixture1_sample.ts"
1823
(async () => {
1924
const { dedent } = await import('ts-dedent');
2025
const S = await import('@effect/schema');
21-
const Fx = await import('./tests/project_simulation/generated/fixture1/fixture1.ts');
26+
const Fx = await import('../project_simulation/generated/fixture1/fixture1.ts');
2227
2328
console.log(dedent`
2429
import { pipe } from 'effect';
@@ -53,10 +58,10 @@ cat <<"EOT" | npm run --silent node | prettier --parser=babel-ts --single-quote
5358
EOT
5459
echo 'Done!'
5560

56-
npm run node "${TEST_OUTPUT_PATH}/fixture1_sample.ts"
61+
node --import=tsx "${TEST_OUTPUT_PATH}/fixture1_sample.ts"
5762

5863

5964
# Type check the output
6065
# Note: no way to call `tsc` with a `tsconfig.json` while overriding the input file path dynamically, need to use
6166
# a specialized `tsconfig.json` file that extends the base config.
62-
tsc --project "${PATH_CURRENT}/tsconfig.json"
67+
npx --silent tsc --project tsconfig.json

0 commit comments

Comments
 (0)