Skip to content

Commit

Permalink
Support for flow
Browse files Browse the repository at this point in the history
Close #562
Close #561
  • Loading branch information
newtang authored and isaacs committed May 28, 2019
1 parent 51772bb commit 0d2e33f
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/jack.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ Much more documentation available at: https://www.node-tap.org/
description: `Run .js and .mjs with support for EcmaScript modules
(Default: true)`,
}),
flow: flag({
description: `Removes flow types`,
}),

ts: flag({
default: process.env.TAP_NO_TS !== '1',
Expand Down
5 changes: 5 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const path = require('path')
const exists = require('fs-exists-cached').sync
const os = require('os')
const tsNode = require.resolve('ts-node/register')
const flowNode = require.resolve("flow-remove-types/register");
const esm = require.resolve('esm')
const jsx = require.resolve('./jsx.js')
const mkdirp = require('mkdirp').sync
Expand All @@ -22,6 +23,7 @@ const {ProcessDB} = require('istanbul-lib-processinfo')
const rimraf = require('rimraf').sync
const {Repl} = require('../lib/repl.js')


/* istanbul ignore next */
const debug = process.env.TAP_DEBUG === '1'
|| /\btap\b/.test(process.env.NODE_DEBUG) ? (...args) => {
Expand Down Expand Up @@ -602,6 +604,9 @@ const runAllFiles = (options, tap) => {
if (options.jobs > 1)
opt.buffered = isParallelOk(parallelOk, file) !== false

if (options.flow)
options['node-arg'].push('-r', flowNode)

if (options.ts && /\.tsx?$/.test(file)) {
debug('ts file', file)
const compilerOpts = JSON.stringify({
Expand Down
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"domain-browser": "^1.2.0",
"esm": "^3.2.25",
"findit": "^2.0.0",
"flow-remove-types": "^2.99.0",
"foreground-child": "^1.3.3",
"fs-exists-cached": "^1.0.0",
"function-loop": "^1.0.2",
Expand Down
8 changes: 8 additions & 0 deletions tap-snapshots/test-run-dump-config.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ coverage-report: []
debug: false
esm: false
files: []
flow: false
functions: 100
grep: []
help: false
Expand Down Expand Up @@ -67,6 +68,7 @@ coverage-report: []
debug: false
esm: false
files: []
flow: false
functions: 100
grep: []
help: false
Expand Down Expand Up @@ -115,6 +117,7 @@ coverage-report: []
debug: false
esm: false
files: []
flow: false
functions: 100
grep: []
help: false
Expand Down Expand Up @@ -163,6 +166,7 @@ coverage-report: []
debug: false
esm: false
files: []
flow: false
functions: 100
grep: []
help: false
Expand Down Expand Up @@ -211,6 +215,7 @@ coverage-report: []
debug: false
esm: false
files: []
flow: false
functions: 100
grep: []
help: false
Expand Down Expand Up @@ -259,6 +264,7 @@ coverage-report: []
debug: false
esm: false
files: []
flow: false
functions: 100
grep: []
help: false
Expand Down Expand Up @@ -309,6 +315,7 @@ coverage-report:
debug: true
esm: false
files: []
flow: false
functions: 100
grep:
- x
Expand Down Expand Up @@ -368,6 +375,7 @@ coverage-report: []
debug: false
esm: false
files: []
flow: false
functions: 100
grep: []
help: false
Expand Down
32 changes: 32 additions & 0 deletions tap-snapshots/test-run-flow.js-TAP.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/run/flow.js TAP flow > must match snapshot 1`] = `
TAP version 13
ok 1 - cli-tests/flow/ok.js # {time} {
ok 1 - this is fine
1..1
# {time}
}
1..1
# {time}
`

exports[`test/run/flow.js TAP flow manually > must match snapshot 1`] = `
TAP version 13
ok 1 - cli-tests/flow/ok2.js # {time} {
ok 1 - this is fine
1..1
# {time}
}
1..1
# {time}
`
45 changes: 45 additions & 0 deletions test/run/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const {
tmpfile,
run,
tap,
t,
} = require('./')


t.test('flow', t => {
const ok = tmpfile(t, 'flow/ok.js', `
// @flow
const t = require(${tap})
function square(n: number): number {
return n * n;
}
t.pass('this is fine')
`)

const args = [ok, '--flow']

run(args, {}, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(o)
t.end()
})
})

t.test('flow manually', t => {
const ok = tmpfile(t, 'flow/ok2.js', `
// @flow
const t = require(${tap})
function square(n: number): number {
return n * n;
}
t.pass('this is fine')
`)

const args = [ok, '--node-arg=--require', '--node-arg=flow-remove-types/register']

run(args, {}, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(o)
t.end()
})
})

0 comments on commit 0d2e33f

Please sign in to comment.