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 912261443a
refactor: build context and run tests after gathering facts (#26)
* refactor: build context and run tests after gathering facts

* test: update integration test to not check for case collection

* refactor: further cleanup

* refactor: leftover log statements

* refactor: further cleaning

* refactor: no more collector
2023-04-15 21:09:04 -04:00

53 lines
1.5 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')
} 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)
})