diff --git a/bin/jack.js b/bin/jack.js index 2316a9976..1f3b4cf3f 100644 --- a/bin/jack.js +++ b/bin/jack.js @@ -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', diff --git a/bin/run.js b/bin/run.js index 013fe3f76..d589ea584 100755 --- a/bin/run.js +++ b/bin/run.js @@ -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 @@ -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) => { @@ -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({ diff --git a/package-lock.json b/package-lock.json index c0642c69a..bfc87a6f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1026,6 +1026,21 @@ "resolved": "https://registry.npmjs.org/findit/-/findit-2.0.0.tgz", "integrity": "sha1-ZQnwEmr0wXhVHPqZOU4DLhOk1W4=" }, + "flow-parser": { + "version": "0.99.0", + "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.99.0.tgz", + "integrity": "sha512-6opkcL97qs5MhXqP9X/jym0lia6jsqyHpA+Z+6GlJv3bPOfmR45WACEwubJCXv0rMS1ryGF+E5ONzRpxzSoGZQ==" + }, + "flow-remove-types": { + "version": "2.99.0", + "resolved": "https://registry.npmjs.org/flow-remove-types/-/flow-remove-types-2.99.0.tgz", + "integrity": "sha512-xPkxMExWtX/qJ9HnWOTHHN5Aniv7tYPAzjPl70/sh6BPdD0TzufyDBzjp4gy+tKHyE/aWX8qHbnpsU1yb0iLDg==", + "requires": { + "flow-parser": "^0.99.0", + "pirates": "^3.0.2", + "vlq": "^0.2.1" + } + }, "foreground-child": { "version": "1.5.6", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-1.5.6.tgz", @@ -1857,6 +1872,11 @@ "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" }, + "node-modules-regexp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-modules-regexp/-/node-modules-regexp-1.0.0.tgz", + "integrity": "sha1-jZ2+KJZKSsVxLpExZCEHxx6Q7EA=" + }, "normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", @@ -2123,6 +2143,14 @@ "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==" }, + "pirates": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/pirates/-/pirates-3.0.2.tgz", + "integrity": "sha512-c5CgUJq6H2k6MJz72Ak1F5sN9n9wlSlJyEnwvpm9/y3WB4E3pHBDT2c6PEiS1vyJvq2bUxUAIu0EGf8Cx4Ic7Q==", + "requires": { + "node-modules-regexp": "^1.0.0" + } + }, "pkg-dir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", @@ -2840,6 +2868,11 @@ "extsprintf": "^1.2.0" } }, + "vlq": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/vlq/-/vlq-0.2.3.tgz", + "integrity": "sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==" + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 7e68b8aac..05880f574 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tap-snapshots/test-run-dump-config.js-TAP.test.js b/tap-snapshots/test-run-dump-config.js-TAP.test.js index 1e0ed0883..961d8e4e8 100644 --- a/tap-snapshots/test-run-dump-config.js-TAP.test.js +++ b/tap-snapshots/test-run-dump-config.js-TAP.test.js @@ -19,6 +19,7 @@ coverage-report: [] debug: false esm: false files: [] +flow: false functions: 100 grep: [] help: false @@ -67,6 +68,7 @@ coverage-report: [] debug: false esm: false files: [] +flow: false functions: 100 grep: [] help: false @@ -115,6 +117,7 @@ coverage-report: [] debug: false esm: false files: [] +flow: false functions: 100 grep: [] help: false @@ -163,6 +166,7 @@ coverage-report: [] debug: false esm: false files: [] +flow: false functions: 100 grep: [] help: false @@ -211,6 +215,7 @@ coverage-report: [] debug: false esm: false files: [] +flow: false functions: 100 grep: [] help: false @@ -259,6 +264,7 @@ coverage-report: [] debug: false esm: false files: [] +flow: false functions: 100 grep: [] help: false @@ -309,6 +315,7 @@ coverage-report: debug: true esm: false files: [] +flow: false functions: 100 grep: - x @@ -368,6 +375,7 @@ coverage-report: [] debug: false esm: false files: [] +flow: false functions: 100 grep: [] help: false diff --git a/tap-snapshots/test-run-flow.js-TAP.test.js b/tap-snapshots/test-run-flow.js-TAP.test.js new file mode 100644 index 000000000..05c118352 --- /dev/null +++ b/tap-snapshots/test-run-flow.js-TAP.test.js @@ -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} + +` diff --git a/test/run/flow.js b/test/run/flow.js new file mode 100644 index 000000000..48e681b31 --- /dev/null +++ b/test/run/flow.js @@ -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() + }) +}) \ No newline at end of file