Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const getFullConfig = async ({

// test runner configuration
const isNodeTest = pkgConfig.testRunner === 'node:test'
const coverageThreshold = pkgConfig.coverageThreshold ?? 100

// all derived keys
const derived = {
Expand Down Expand Up @@ -173,6 +174,7 @@ const getFullConfig = async ({
deleteJsExt: esm ? 'js' : 'cjs',
// test runner
isNodeTest,
coverageThreshold,
// tap
// 18 and up doesn't like nyc-arg
tap18: !isNodeTest && semver.coerce(pkg.pkgJson?.devDependencies?.tap)?.major >= 18,
Expand Down
6 changes: 3 additions & 3 deletions lib/content/package-json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
{{#if isNodeTest}}
"snap": "node --test --test-update-snapshots",
"test": "node --test",
"test:cover": "node --test --experimental-test-coverage --test-timeout=3000 --test-coverage-lines=100 --test-coverage-functions=100 --test-coverage-branches=100",
"snap": "node --test --test-update-snapshots ./test/**/*.js",
"test": "node --test ./test/**/*.js",
"test:cover": "node --test --experimental-test-coverage --test-timeout=3000{{#if coverageThreshold}} --test-coverage-lines={{coverageThreshold}} --test-coverage-functions={{coverageThreshold}} --test-coverage-branches={{coverageThreshold}}{{/if}} ./test/**/*.js",
{{else}}
"snap": "{{#if typescript}}{{#if tap16}}c8 {{/if}}{{/if}}tap",
"test": "{{#if typescript}}{{#if tap16}}c8 {{/if}}{{/if}}tap",
Expand Down
30 changes: 27 additions & 3 deletions test/apply/node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ t.test('node:test runner', async t => {
const pkg = await s.readJson('package.json')

// Verify test scripts are for node:test
t.equal(pkg.scripts.test, 'node --test')
t.equal(pkg.scripts.test, 'node --test ./test/**/*.js')
t.equal(
pkg.scripts['test:cover'],
'node --test --experimental-test-coverage --test-timeout=3000 --test-coverage-lines=100 --test-coverage-functions=100 --test-coverage-branches=100',
'node --test --experimental-test-coverage --test-timeout=3000 --test-coverage-lines=100 --test-coverage-functions=100 --test-coverage-branches=100 ./test/**/*.js',
)
t.equal(pkg.scripts.snap, 'node --test --test-update-snapshots')
t.equal(pkg.scripts.snap, 'node --test --test-update-snapshots ./test/**/*.js')

// Verify tap section is removed
t.notOk(pkg.tap, 'tap section should not be present')
Expand All @@ -36,6 +36,30 @@ t.test('node:test runner', async t => {
}
})

t.test('node:test runner with incomplete coverage', async t => {
const s = await setup(t, {
ok: true,
package: {
templateOSS: {
testRunner: 'node:test',
coverageThreshold: 0,
},
},
})

await s.apply()
const pkg = await s.readJson('package.json')

// Verify test scripts are for node:test
t.equal(pkg.scripts.test, 'node --test ./test/**/*.js')
t.equal(
pkg.scripts['test:cover'],
'node --test --experimental-test-coverage --test-timeout=3000 ./test/**/*.js',
'test:cover should not include coverage thresholds when coverageThreshold is 0',
)
t.equal(pkg.scripts.snap, 'node --test --test-update-snapshots ./test/**/*.js')
})

t.test('tap runner (default)', async t => {
const s = await setup(t, {
ok: true,
Expand Down