Skip to content

Commit

Permalink
Support 10.0 and test in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Mar 30, 2021
1 parent dc5c841 commit c44c418
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 15.x]
node-version: [10.0, 10.x, 12.0, 12.x, 14.0, 14.x, 15.x]
os: [ubuntu-latest]

steps:
Expand Down
5 changes: 5 additions & 0 deletions bin/run.js
Expand Up @@ -699,8 +699,13 @@ const runAllFiles = (options, env, tap, processDB) => {
tap.spawn(node, args, opt, file)
} else if (/\.jsx$|\.tsx?$|\.[mc]?js$/.test(file)) {
debug('js file', file)
/* istanbul ignore next - version specific behavior */
const experimental = /^v10\./.test(process.version) && /\.mjs$/.test(file)
? ['--experimental-modules'] : []

const args = [
...options['node-arg'],
...experimental,
file,
...options['test-arg']
]
Expand Down
7 changes: 7 additions & 0 deletions lib/tap.js
Expand Up @@ -2,6 +2,13 @@
const {deprecate} = require('util')

const settings = require('../settings.js')
/* istanbul ignore next - version specific */
if (settings.rimrafNeeded) {
const rimraf = require('rimraf')
settings.rmdirRecursive = (path, cb) => rimraf(path, { glob: false }, cb)
settings.rmdirRecursiveSync = path => rimraf.sync(path, { glob: false })
}

const tap = require('libtap')
// Needs to be set before requiring mocha.js
module.exports = tap
Expand Down
4 changes: 2 additions & 2 deletions tap-snapshots/test/settings/default.js.test.cjs
Expand Up @@ -10,8 +10,8 @@ Object {
"atTap": false,
"output": true,
"rimrafNeeded": false,
"rmdirRecursive": Function rmdirRecursive(dir, cb),
"rmdirRecursiveSync": Function rmdirRecursiveSync(dir),
"rmdirRecursive": "function(path, cb)",
"rmdirRecursiveSync": "function(path)",
"snapshotFile": Function snapshotFile(cwd, main, argv),
"stackUtils": Object {
"ignoredPackages": Array [
Expand Down
4 changes: 2 additions & 2 deletions tap-snapshots/test/settings/long-stack.js.test.cjs
Expand Up @@ -10,8 +10,8 @@ Object {
"atTap": true,
"output": true,
"rimrafNeeded": false,
"rmdirRecursive": Function rmdirRecursive(dir, cb),
"rmdirRecursiveSync": Function rmdirRecursiveSync(dir),
"rmdirRecursive": "function(path, cb)",
"rmdirRecursiveSync": "function(path)",
"snapshotFile": Function snapshotFile(cwd, main, argv),
"stackUtils": Object {
"ignoredPackages": Array [],
Expand Down
3 changes: 2 additions & 1 deletion test/run/comments.js
Expand Up @@ -3,6 +3,7 @@ const {
run,
tap,
t,
clean,
} = require('./')

const ok = tmpfile(t, 'comments/ok.js', `'use strict'
Expand All @@ -20,4 +21,4 @@ const ok = tmpfile(t, 'comments/ok.js', `'use strict'

t.plan(1)
run(['--comments', ok], {}, (er, o, e) =>
t.equal(e, 'root\nparent\nchild\n'))
t.equal(clean(e), 'root\nparent\nchild\n'))
3 changes: 2 additions & 1 deletion test/run/env.js
Expand Up @@ -3,6 +3,7 @@ const {
run,
tap,
t,
clean,
} = require('./')

const ok = tmpfile(t, 'ok.js', `
Expand All @@ -15,6 +16,6 @@ const ok = tmpfile(t, 'ok.js', `
t.plan(3)
run(['--test-env=USER', '--test-env=TERM=', '--test-env=glorp=foo', ok], {}, (er, o, e) => {
t.notOk(er)
t.equal(e, '')
t.equal(clean(e), '')
t.matchSnapshot(o)
})
5 changes: 3 additions & 2 deletions test/run/files.js
Expand Up @@ -3,6 +3,7 @@ const {
run,
tap,
t,
clean,
} = require('./')
const yaml = require('tap-yaml')

Expand All @@ -25,7 +26,7 @@ t.test('--files work like explicit positional argument', t => {
t.plan(3)
run([`--files=${one}`, `--files=${two}`], {}, (er, o, e) => {
t.notOk(er)
t.equal(e, '')
t.equal(clean(e), '')
t.matchSnapshot(o)
})
})
Expand All @@ -34,7 +35,7 @@ t.test('--files do not override explicit positional argument', t => {
t.plan(3)
run([`--files=${one}`, `--files=${two}`, three], {}, (er, o, e) => {
t.notOk(er)
t.equal(e, '')
t.equal(clean(e), '')
t.matchSnapshot(o)
})
})
3 changes: 3 additions & 0 deletions test/run/index.js
Expand Up @@ -19,6 +19,7 @@ delete process.env.TAP_COLORS
delete process.env.TAP_TIMEOUT

const winSkip = process.platform === 'win32' ? 'known windows failure' : false
const oldSkip = /^v10\./.test(process.version) ? 'known node v10 failure': false

const cleanStacks = require('../clean-stacks.js')
// also clean up NYC output a bit, because the line lengths
Expand All @@ -32,6 +33,7 @@ const clean = string => cleanStacks(string)
// two that show up in config dump snapshots
.replace(/snapshot: (true|false)\n/, '')
.replace(/cli-tests-[0-9]+/g, 'cli-tests')
.split('\n').filter(l => !/ExperimentalWarning/.test(l)).join('\n')

t.cleanSnapshot = clean

Expand Down Expand Up @@ -110,4 +112,5 @@ module.exports = {
dir,
t,
winSkip,
oldSkip,
}
19 changes: 10 additions & 9 deletions test/run/libtap-settings.js
Expand Up @@ -3,6 +3,7 @@ const {
run,
tap,
t,
clean,
} = require('./')

const { resolve } = require('path')
Expand Down Expand Up @@ -52,7 +53,7 @@ const settings = n => `--libtap-settings=settings/${n}.js`
t.test('print out a different snapshot file location', t => {
run([settings('ok'), testFile], {cwd: path}, (er, o, e) => {
t.notOk(er)
t.equal(e, '')
t.equal(clean(e), '')
t.matchSnapshot(o)
t.end()
})
Expand All @@ -61,7 +62,7 @@ t.test('print out a different snapshot file location', t => {
t.test('print out the normal snapshot file location', t => {
run([settings('ok-empty'), testFile], {cwd: path}, (er, o, e) => {
t.notOk(er)
t.equal(e, '')
t.equal(clean(e), '')
t.matchSnapshot(o)
t.end()
})
Expand All @@ -70,7 +71,7 @@ t.test('print out the normal snapshot file location', t => {
t.test('fails if module not found', t => {
run([settings('does-not-exist'), testFile], {cwd: path}, (er, o, e) => {
t.match(er, { code: 1 })
t.match(e, 'Error: ') // specific msg different across node versions
t.match(clean(e), 'Error: ') // specific msg different across node versions
t.equal(o, '')
t.end()
})
Expand All @@ -79,7 +80,7 @@ t.test('fails if module not found', t => {
t.test('adding an unknown field is invalid', t => {
run([settings('unknown-field'), testFile], {cwd: path}, (er, o, e) => {
t.match(er, { code: 1 })
t.match(e, 'Error: Unrecognized libtap setting: foo')
t.match(clean(e), 'Error: Unrecognized libtap setting: foo')
t.equal(o, '')
t.end()
})
Expand All @@ -88,7 +89,7 @@ t.test('adding an unknown field is invalid', t => {
t.test('fields must be same type as libtap defines', t => {
run([settings('wrong-type-field'), testFile], {cwd: path}, (er, o, e) => {
t.match(er, { code: 1 })
t.match(e, 'Error: Invalid type for libtap setting snapshotFile. Expected function, received number.')
t.match(clean(e), 'Error: Invalid type for libtap setting snapshotFile. Expected function, received number.')
t.equal(o, '')
t.end()
})
Expand All @@ -97,7 +98,7 @@ t.test('fields must be same type as libtap defines', t => {
t.test('exporting function is invalid', t => {
run([settings('export-function'), testFile], {cwd: path}, (er, o, e) => {
t.match(er, { code: 1 })
t.match(e, 'Error: invalid libtap settings: function')
t.match(clean(e), 'Error: invalid libtap settings: function')
t.equal(o, '')
t.end()
})
Expand All @@ -106,7 +107,7 @@ t.test('exporting function is invalid', t => {
t.test('exporting array is invalid', t => {
run([settings('export-array'), testFile], {cwd: path}, (er, o, e) => {
t.match(er, { code: 1 })
t.match(e, 'Error: invalid libtap settings: array')
t.match(clean(e), 'Error: invalid libtap settings: array')
t.equal(o, '')
t.end()
})
Expand All @@ -115,7 +116,7 @@ t.test('exporting array is invalid', t => {
t.test('exporting false is invalid', t => {
run([settings('export-false'), testFile], {cwd: path}, (er, o, e) => {
t.match(er, { code: 1 })
t.match(e, 'Error: invalid libtap settings: boolean')
t.match(clean(e), 'Error: invalid libtap settings: boolean')
t.equal(o, '')
t.end()
})
Expand All @@ -124,7 +125,7 @@ t.test('exporting false is invalid', t => {
t.test('exporting null is invalid', t => {
run([settings('export-null'), testFile], {cwd: path}, (er, o, e) => {
t.match(er, { code: 1 })
t.match(e, 'Error: invalid libtap settings: null')
t.match(clean(e), 'Error: invalid libtap settings: null')
t.equal(o, '')
t.end()
})
Expand Down
3 changes: 2 additions & 1 deletion test/run/nocolor-env.js
Expand Up @@ -5,6 +5,7 @@ const {
run,
tap,
t,
clean,
} = require('./')

const ok = tmpfile(t, 'ok.js', `
Expand All @@ -19,6 +20,6 @@ run([ok], {
}
}, (er, o, e) => {
t.notOk(er)
t.equal(e, '')
t.equal(clean(e), '')
t.matchSnapshot(o)
})
2 changes: 1 addition & 1 deletion test/run/reporters.js
Expand Up @@ -24,7 +24,7 @@ const check = t => (er, o, e) => {
.replace(/^[\S\s]*SUMMARY RESULTS[\S\s]*$/,'treport output')
.replace(/^[\S\s]*✓[\S\s]*$/, 'spec output')
t.matchSnapshot(o, 'stdout')
t.equal(e, '', 'stderr')
t.equal(clean(e), '', 'stderr')
t.end()
}

Expand Down
14 changes: 8 additions & 6 deletions test/run/save-file.js
Expand Up @@ -7,6 +7,8 @@ const {
dir,
t,
winSkip,
oldSkip,
clean,
} = require('./')

const path = require('path')
Expand Down Expand Up @@ -36,8 +38,8 @@ const opt = { cwd: dir, env: {} }
t.test('with bailout, should save all untested', t => {
run(['a', 'x', 'z.js', '-s', savefile, '-b'], opt, (er, o, e) => {
t.match(er, { code: 1 })
t.matchSnapshot(o, 'stdout', { skip: winSkip })
t.equal(e, '')
t.matchSnapshot(o, 'stdout', { skip: winSkip || oldSkip })
t.equal(clean(e), '')
t.matchSnapshot(fs.readFileSync(savefile, 'utf8'), 'savefile')
t.end()
})
Expand All @@ -46,8 +48,8 @@ t.test('with bailout, should save all untested', t => {
t.test('without bailout, run untested, save failures', t => {
run(['a', 'x', 'z.js', '-s', savefile], opt, (er, o, e) => {
t.match(er, { code: 1 })
t.matchSnapshot(o, 'stdout', { skip: winSkip })
t.equal(e, '')
t.matchSnapshot(o, 'stdout', { skip: winSkip || oldSkip })
t.equal(clean(e), '')
t.matchSnapshot(fs.readFileSync(savefile, 'utf8'), 'savefile')
t.end()
})
Expand All @@ -67,7 +69,7 @@ t.test('pass, empty save file', t => {
run(['a', 'x', 'z.js', '-s', savefile], opt, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(o, 'stdout')
t.equal(e, '')
t.equal(clean(e), '')
try {
console.log(fs.readFileSync(savefile, 'utf8'))
} catch (e) {}
Expand All @@ -80,7 +82,7 @@ t.test('empty save file, run all tests', t => {
run(['a', 'x', 'z.js', '-s', savefile], opt, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(o, 'stdout')
t.equal(e, '')
t.equal(clean(e), '')
t.throws(() => fs.statSync(savefile), 'save file is gone')
t.end()
})
Expand Down
5 changes: 4 additions & 1 deletion test/settings/clean-for-snapshot.js
Expand Up @@ -10,5 +10,8 @@ module.exports = settings => ({
stackUtils: {
...settings.stackUtils,
internals: []
}
},
rimrafNeeded: false,
rmdirRecursive: 'function(path, cb)',
rmdirRecursiveSync: 'function(path)',
})
5 changes: 4 additions & 1 deletion test/test-esm.js
Expand Up @@ -14,6 +14,9 @@ const {join} = require('path')
const testPath = join(__dirname, './test.mjs')

t.test('test esm entry point', t => {
t.spawn('node', [testPath])
const arg = [testPath]
if (/^v10\./.test(process.version))
arg.unshift('--experimental-modules')
t.spawn('node', arg)
t.end()
})
10 changes: 9 additions & 1 deletion test/test.mjs
@@ -1,7 +1,15 @@
import {createRequire} from 'module'
import * as module from 'module'
const { createRequire } = module

import * as tap from 'tap'

if (typeof createRequire !== 'function') {
console.log(`TAP version 13
1..0 # SKIP - no createRequire function available ${process.version}
`)
process.exit(0)
}

const require = createRequire(import.meta.url);

const cjs = require('tap');
Expand Down

0 comments on commit c44c418

Please sign in to comment.