Skip to content
This repository was archived by the owner on Nov 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!lib/
!settings.js
!versions.js
!istanbul-loader-hook.mjs
!package.json
!package-lock.json
!README.md
Expand Down
3 changes: 3 additions & 0 deletions coverage-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const rootFiles = ['settings', 'versions'];

module.exports = t => {
const parts = path.relative(process.cwd(), path.resolve(t)).split(/\\|\//)
if (parts[1] === 'libtap.mjs')
return 'lib/tap.mjs'

const unit = path.basename(parts[1], '.js')
if (rootFiles.includes(unit))
return `${unit}.js`
Expand Down
14 changes: 14 additions & 0 deletions istanbul-loader-hook.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fileURLToPath } from 'url'
import babel from '@babel/core'

export async function transformSource(source, context, defaultTransformSource) {
const {code} = await babel.transformAsync(source, {
babelrc: false,
configFile: false,
filename: fileURLToPath(context.url),
sourceMaps: 'inline',
plugins: ['babel-plugin-istanbul']
})

return {source: code}
}
31 changes: 31 additions & 0 deletions lib/tap.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import tap from './tap.js'

export const {
Test, Spawn, Stdin,
spawn, sub,
todo, skip, only, test,
stdinOnly, stdin,
bailout,
comment,
timeout,
main,
process,
processSubtest,
addAssert,
pragma,
plan, end,
beforeEach,
afterEach,
teardown,
autoend,
pass, fail, ok, notOk,
emits,
error, equal, not, same, notSame, strictSame, strictNotSame,
testdir, fixture,
matchSnapshot,
hasStrict, match, notMatch, type,
expectUncaughtException, throwsArgs, throws, doesNotThrow,
rejects, resolves, resolveMatch, resolveMatchSnapshot
} = tap

export default tap
12 changes: 10 additions & 2 deletions npm-run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
const foregroundChild = require('foreground-child')

async function runTests() {
const semver = require('semver')
const glob = require('glob')
const os = require('os')
const t = require('.')
const coverageMap = require('./coverage-map.js')
const testESM = semver.gte(process.versions.node, '13.10.0')
const testFileGlob = testESM ? 'test/**/*.{js,mjs}' : 'test/**/*.js'
const esLoaderHook = {
NODE_OPTIONS: `${process.env.NODE_OPTIONS || ''} --experimental-loader "${require.resolve('./istanbul-loader-hook.mjs')}"`
}

t.jobs = os.cpus().length

glob.sync('test/**/*.js').forEach(file => {
glob.sync(testFileGlob).forEach(file => {
const esLoaderEnv = file.endsWith('.mjs') ? esLoaderHook : {}
t.spawn(
process.execPath,
[file],
Expand All @@ -20,7 +27,8 @@ async function runTests() {
...process.env,
NYC_CONFIG_OVERRIDE: JSON.stringify({
include: coverageMap(file) || ''
})
}),
...esLoaderEnv
}
},
file
Expand Down
3 changes: 3 additions & 0 deletions nyc.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
'use strict'

const semver = require('semver')

module.exports = {
all: true,
checkCoverage: true,
lines: 100,
functions: 100,
branches: 100,
statements: 100,
extension: semver.gte(process.versions.node, '13.10.0') ? ['.js', '.mjs'] : ['.js'],
include: [
'settings.js',
'versions.js',
Expand Down
Loading