This repository has been archived on 2024-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
works-on-my-machine/integration/requires-ts-node-for-ts-tests.ts
Marc Cataford e6ef369fdb
build: ts-node no longer needed in main install (#24)
* build: ts-node no longer needed in main install

* test: integration tests can use regular build package
2023-04-15 01:37:05 -04:00

54 lines
1.6 KiB
TypeScript

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 ../package.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)
})