diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index d6dbc17..dcec5dd 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -44,7 +44,30 @@ jobs: key: ${{ runner.os }}-build-${{env.cache-name}}-${{ hashFiles('**/yarn.lock') }}-node-${{ matrix.node-version }} - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} run: corepack enable && yarn + integration: + runs-on: ubuntu-latest + needs: dependencies + name: Integration tests + + strategy: + matrix: + node-version: [16, 18] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/cache@v3 + id: dependencies-cache + env: + cache-name: dependencies-cache + with: + path: .yarn + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}-node-${{ matrix.node-version }} + - run: | + corepack enable && yarn + yarn test:integration lint: runs-on: ubuntu-latest needs: dependencies diff --git a/integration/requires-ts-node-for-ts-tests.ts b/integration/requires-ts-node-for-ts-tests.ts new file mode 100644 index 0000000..439dd8f --- /dev/null +++ b/integration/requires-ts-node-for-ts-tests.ts @@ -0,0 +1,54 @@ +import assert from 'assert' +import { promises as fs } from 'fs' +import util from 'util' +import childProcess from 'child_process' + +const exec = util.promisify(childProcess.exec) + +const TEST_ID = "requires-ts-node-for-ts-tests" +const TEST_DIRECTORY = `integration-test-${TEST_ID}` + +const execOptions = { cwd: TEST_DIRECTORY } + +async function setUp() { + await fs.mkdir(TEST_DIRECTORY) + await fs.writeFile(`${TEST_DIRECTORY}/package.json`, JSON.stringify({})) + await exec('touch yarn.lock', execOptions) + await exec('yarn add ../integration-build.tgz', execOptions) +} + +async function tearDown() { + await fs.rm(TEST_DIRECTORY, { recursive: true, force: true }) +} + +/* + * The runner skips Typescript files if the --ts flag is not used. + * A notice is printed about the skipped files. + */ +async function requires_ts_node_for_ts_tests() { + try { + await setUp() + + await exec('touch sample.test.ts', execOptions) + const processOut = await exec('womm .', execOptions) + + const stdout = processOut.stdout + + assert.ok(stdout.includes('sample.test.ts is not supported without --ts and will be ignored'), 'Unsupported test notice not found') + assert.ok(stdout.includes('Collected 0 test files'), 'Did not find notice of no test collected') + assert.ok(stdout.includes('Collected 0 test cases'), 'Did not find notice of no cases collected') + } catch(e) { + await tearDown() + console.log(e) + assert.fail(`[FAILED] ${TEST_ID}`) + } + + await tearDown() + + console.log(`[PASS] ${TEST_ID}`) +} + +requires_ts_node_for_ts_tests().catch((e) => { + console.error(e) + process.exit(1) +}) diff --git a/package.json b/package.json index c87de5e..6b11794 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "lint": "rome format src tests && rome check src tests", "lint:fix": "rome format src tests --write && rome check src tests --apply", "test": "ts-node ./src/cli.ts ./tests", + "test:integration": "/usr/bin/bash ./script/integration-tests", "build": "tsc --project ." }, "devDependencies": { diff --git a/script/integration-tests b/script/integration-tests new file mode 100644 index 0000000..d51c921 --- /dev/null +++ b/script/integration-tests @@ -0,0 +1,7 @@ +#!/usr/bin/bash + +yarn pack --out integration-build.tgz + +for filename in $(find ./integration -type f -print); do + ts-node $filename; +done diff --git a/script/lint-commits b/script/lint-commits index 1d4679e..a9e98b6 100644 --- a/script/lint-commits +++ b/script/lint-commits @@ -11,8 +11,7 @@ # CURRENT_HEAD=$(git rev-parse HEAD) -BASE_HEAD=$(git log origin/main..$CURRENT_HEAD --oneline --format=%H | tail -1) -COMMITS=$(git log $BASE_HEAD..$CURRENT_HEAD --oneline --format=%s) +COMMITS=$(git log origin/main..$CURRENT_HEAD --oneline --format=%s) if [[ -z "$COMMITS" ]]; then echo "No commits." @@ -24,7 +23,7 @@ INVALID_COMMITS_FOUND=0 while IFS='\n' read -r line; do if [[ $line =~ ^"Merge "[0-9a-z]+" into "[0-9a-z]+$ ]]; then continue - elif [[ ($line =~ ^(feat|chore|fix|refactor|wip|docs|build|ci|perf):) ]]; then + elif [[ ($line =~ ^(test|feat|chore|fix|refactor|wip|docs|build|ci|perf):) ]]; then echo "VALID - $line" else echo "INVALID - $line" diff --git a/src/runner.ts b/src/runner.ts index 2d4ede0..dacbbb7 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -130,17 +130,13 @@ async function run(args: Args, context: Context) { performance.mark('test-collect:end') const testCollectTime = performance.measure('test-collect', 'test-collect:start', 'test-collect:end').duration - console.log( - `Collected ${boldText(supportedTests.length)} test files in ${boldText((testCollectTime / 1000).toFixed(3))}s`, - ) + console.log(`Collected ${supportedTests.length} test files in ${boldText((testCollectTime / 1000).toFixed(3))}s`) performance.mark('case-collect:start') const collectedCaseCount = await collectCases(context, supportedTests) performance.mark('case-collect:end') const caseCollectTime = performance.measure('case-collect', 'case-collect:start', 'case-collect:end').duration - console.log( - `Collected ${boldText(collectedCaseCount)} test cases in ${boldText((caseCollectTime / 1000).toFixed(3))}s`, - ) + console.log(`Collected ${collectedCaseCount} test cases in ${boldText((caseCollectTime / 1000).toFixed(3))}s`) const summary = await assignTestsToWorkers(context, supportedTests, args.workers) const hasFailed = Object.values(summary).filter((workerReport) => !workerReport.pass).length > 0