From 4629090fb2e298e21366b336cd514ca42bd1686a Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 14 Dec 2023 23:28:27 +0100 Subject: [PATCH] Add Windows to CI (#1) * Add Windows to CI Signed-off-by: Matteo Collina * fixup Signed-off-by: Matteo Collina * fixup Signed-off-by: Matteo Collina * fixup Signed-off-by: Matteo Collina * fixup Signed-off-by: Matteo Collina * fixup Signed-off-by: Matteo Collina * fixup Signed-off-by: Matteo Collina * fixup Signed-off-by: Matteo Collina --------- Signed-off-by: Matteo Collina --- .github/workflows/ci.yml | 3 ++- borp.js | 8 +++++++- fixtures/fails/test/wrong.test.js | 6 ++++++ lib/run.js | 7 ++++--- package.json | 2 +- test/cli.test.js | 10 ++++++++++ 6 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 fixtures/fails/test/wrong.test.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd9d738..0c447b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,11 +12,12 @@ on: jobs: test: - runs-on: ubuntu-latest + runs-on: ${{matrix.os}} strategy: matrix: node-version: [18.x, 20.x, 21.x] + os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v3 diff --git a/borp.js b/borp.js index ca86912..7e207a0 100755 --- a/borp.js +++ b/borp.js @@ -5,6 +5,7 @@ import { tap, spec } from 'node:test/reporters' import { mkdtemp, rm } from 'node:fs/promises' import { finished } from 'node:stream/promises' import { join, relative } from 'node:path' +import posix from 'node:path/posix' import runWithTypeScript from './lib/run.js' import { Report } from 'c8' @@ -55,6 +56,10 @@ const config = { try { const stream = await runWithTypeScript(config) + stream.on('test:fail', () => { + process.exitCode = 1 + }) + stream.compose(reporter).pipe(process.stdout) await finished(stream) @@ -66,8 +71,9 @@ try { exclude = undefined } else if (config.prefix) { const localPrefix = relative(process.cwd(), config.prefix) - exclude = exclude.map((file) => join(localPrefix, file)) + exclude = exclude.map((file) => posix.join(localPrefix, file)) } + console.log('>> Excluding from coverage:', exclude) const report = Report({ reporter: ['text'], tempDirectory: covDir, diff --git a/fixtures/fails/test/wrong.test.js b/fixtures/fails/test/wrong.test.js new file mode 100644 index 0000000..30fc1e2 --- /dev/null +++ b/fixtures/fails/test/wrong.test.js @@ -0,0 +1,6 @@ +import { strictEqual } from 'node:assert' +import { test } from 'node:test' + +test('this will fail', () => { + strictEqual(1, 2) +}) diff --git a/lib/run.js b/lib/run.js index 92c8b09..6627622 100644 --- a/lib/run.js +++ b/lib/run.js @@ -115,6 +115,7 @@ export default async function runWithTypeScript (config) { } let files = config.files || [] + const ignore = join('node_modules', '**') if (files.length > 0) { if (prefix) { files = files.map((file) => join(prefix, file.replace(/ts$/, 'js'))) @@ -123,11 +124,11 @@ export default async function runWithTypeScript (config) { if (prefix) { config.pattern = join(prefix, config.pattern) } - files = await glob(config.pattern, { ignore: 'node_modules/**', cwd }) + files = await glob(config.pattern, { ignore, cwd, windowsPathsNoEscape: true }) } else if (prefix) { - files = await glob(join(prefix, 'test/**/*.test.{cjs,mjs,js}'), { ignore: 'node_modules/**', cwd }) + files = await glob(join(prefix, join('test', '**', '*.test.{cjs,mjs,js}')), { ignore, cwd, windowsPathsNoEscape: true }) } else { - files = await glob('test/**/*.test.{cjs,mjs,js}', { ignore: 'node_modules/**', cwd }) + files = await glob(join('test', '**', '*.test.{cjs,mjs,js}'), { ignore, cwd, windowsPathsNoEscape: true }) } config.files = files diff --git a/package.json b/package.json index 6b03f6f..76875de 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "clean": "rm -rf fixtures/*/dist .test-* coverage-*", "lint": "standard | snazzy", - "unit": "./borp.js --concurrency=1 --coverage --coverage-exclude 'fixtures/**/*,test/**/*'", + "unit": "node borp.js --concurrency=1 --coverage --coverage-exclude \"fixtures/**/*,test/**/*\"", "test": "npm run clean ; npm run lint && npm run unit" }, "keywords": [], diff --git a/test/cli.test.js b/test/cli.test.js index e922552..e5daa81 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -1,6 +1,7 @@ import { test } from 'node:test' import { execa } from 'execa' import { join } from 'desm' +import { rejects } from 'node:assert' const borp = join(import.meta.url, '..', 'borp.js') @@ -13,3 +14,12 @@ test('limit concurrency', async () => { cwd: join(import.meta.url, '..', 'fixtures', 'ts-esm') }) }) + +test('failing test set correct status code', async () => { + // execa rejects if status code is not 0 + await rejects(execa('node', [ + borp + ], { + cwd: join(import.meta.url, '..', 'fixtures', 'fails') + })) +})