test: add integration test on ts skip (#22)
* test: add integration test on ts skip * chore: add test prefix to commit linter * build: shell access * build: lint commit to include first commit
This commit is contained in:
parent
e7cc91c6ac
commit
540ce0bbbb
6 changed files with 89 additions and 9 deletions
23
.github/workflows/nodejs.yml
vendored
23
.github/workflows/nodejs.yml
vendored
|
@ -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
|
||||
|
|
54
integration/requires-ts-node-for-ts-tests.ts
Normal file
54
integration/requires-ts-node-for-ts-tests.ts
Normal file
|
@ -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)
|
||||
})
|
|
@ -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": {
|
||||
|
|
7
script/integration-tests
Normal file
7
script/integration-tests
Normal file
|
@ -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
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue