Skip to content

Commit

Permalink
test: cover case of a post-compile script with cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Palaxx committed Mar 21, 2024
1 parent 418aa53 commit 4aee1c9
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 3 deletions.
3 changes: 3 additions & 0 deletions fixtures/ts-cjs-post-compile/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
1 change: 1 addition & 0 deletions fixtures/ts-cjs-post-compile/postCompile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Doing stuff')
4 changes: 4 additions & 0 deletions fixtures/ts-cjs-post-compile/src/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export function add (x: number, y: number): number {
return x + y
}
7 changes: 7 additions & 0 deletions fixtures/ts-cjs-post-compile/test/add.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import { add } from '../src/add.js'
import { strictEqual } from 'node:assert'

test('add', () => {
strictEqual(add(1, 2), 3)
})
7 changes: 7 additions & 0 deletions fixtures/ts-cjs-post-compile/test/add2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import { add } from '../src/add.js'
import { strictEqual } from 'node:assert'

test('add2', () => {
strictEqual(add(3, 2), 5)
})
24 changes: 24 additions & 0 deletions fixtures/ts-cjs-post-compile/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"outDir": "dist",
"sourceMap": true,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"strict": true,
"resolveJsonModule": true,
"removeComments": true,
"newLine": "lf",
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"lib": [
"ESNext"
],
"incremental": true
}
}
2 changes: 1 addition & 1 deletion lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default async function runWithTypeScript (config) {
let outDir = ''
if (config['post-compile'] && tsconfigPath) {
const tsconfig = JSON.parse(await readFile(tsconfigPath))
outDir = tsconfig.compilerOptions.outDir ?? ''
outDir = tsconfig.compilerOptions.outDir
}
let start = Date.now()
tscChild = execa('node', [tscPath, ...typescriptCliArgs], { cwd })
Expand Down
13 changes: 12 additions & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('gh reporter', async () => {
strictEqual(stdout.indexOf('::notice') >= 0, true)
})

test('post-compile hook should be correctly called', async () => {
test('Post compile script should be executed when --post-compile is sent with esm', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm-post-compile')
const { stdout } = await execa('node', [
borp,
Expand All @@ -100,3 +100,14 @@ test('post-compile hook should be correctly called', async () => {

strictEqual(stdout.indexOf('Post compile hook complete') >= 0, true, 'Post compile message should be found in stdout')
})

test('Post compile script should be executed when --post-compile is sent with cjs', async () => {
const { stdout } = await execa('node', [
borp,
'--post-compile=postCompile.ts'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'ts-cjs-post-compile')
})

strictEqual(stdout.indexOf('Post compile hook complete') >= 0, true, 'Post compile message should be found in stdout')
})
2 changes: 1 addition & 1 deletion test/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ test('add', () => {
await completed
})

test('watch with post compile hook', async (t) => {
test('watch with post compile hook should call the hook the right number of times', async (t) => {
const { strictEqual, completed, ok } = tspl(t, { plan: 2 })

const dir = path.resolve(await mkdtemp('.test-watch-with-post-compile-hook'))
Expand Down

0 comments on commit 4aee1c9

Please sign in to comment.