diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3b0910..4c247ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [^10.18.0, ^12.14.0, ^13.5.0] + node-version: [^12.22, ^14.16, ^15] os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v1 diff --git a/.gitignore b/.gitignore index 4f52d76..ccc2930 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -/.nyc_output /coverage /node_modules diff --git a/index.js b/index.js index c054114..c48265e 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ function isValidRewritePaths(rewritePaths) { } module.exports = ({negotiateProtocol}) => { - const protocol = negotiateProtocol(['ava-3.2', 'ava-3'], {version: pkg.version}); + const protocol = negotiateProtocol(['ava-3.2'], {version: pkg.version}); if (protocol === null) { return; } diff --git a/package.json b/package.json index 7e1ac53..228b04a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.1.1", "description": "TypeScript provider for AVA", "engines": { - "node": ">=10.18.0 <11 || >=12.14.0 <13 || >=13.5.0" + "node": ">=12.22 <13 || >=14.16 <15 || >=15" }, "files": [ "index.js" @@ -16,18 +16,18 @@ "typescript" ], "scripts": { - "test": "xo && nyc ava" + "test": "xo && c8 ava" }, "dependencies": { - "escape-string-regexp": "^2.0.0" + "escape-string-regexp": "^4.0.0" }, "devDependencies": { - "ava": "^3.0.0", - "execa": "^4.0.0", - "nyc": "^15.0.0", - "xo": "^0.25.3" + "ava": "^3.15.0", + "c8": "^7.7.1", + "execa": "^5.0.0", + "xo": "^0.38.2" }, - "nyc": { + "c8": { "reporter": [ "html", "lcov", diff --git a/test/protocol-ava-3.2.js b/test/protocol-ava-3.2.js index 8400002..82d41d0 100644 --- a/test/protocol-ava-3.2.js +++ b/test/protocol-ava-3.2.js @@ -1,5 +1,6 @@ const path = require('path'); const test = require('ava'); +const execa = require('execa'); const pkg = require('../package.json'); const makeProvider = require('..'); @@ -8,7 +9,7 @@ const withProvider = (t, run) => run(t, makeProvider({ t.true(identifiers.includes('ava-3.2')); t.is(version, pkg.version); return { - ava: {version: '3.2.0'}, + ava: {version: '3.15.0'}, identifier: 'ava-3.2', normalizeGlobPatterns: patterns => patterns, async findFiles({patterns}) { @@ -19,8 +20,60 @@ const withProvider = (t, run) => run(t, makeProvider({ } })); +const validateConfig = (t, provider, config) => { + const error = t.throws(() => provider.main({config})); + error.message = error.message.replace(`v${pkg.version}`, 'v${pkg.version}'); // eslint-disable-line no-template-curly-in-string + t.snapshot(error); +}; + test('negotiates ava-3.2 protocol', withProvider, t => t.plan(2)); +test('main() config validation: throw when config is not a plain object', withProvider, (t, provider) => { + validateConfig(t, provider, false); + validateConfig(t, provider, true); + validateConfig(t, provider, null); + validateConfig(t, provider, []); +}); + +test('main() config validation: throw when config contains keys other than \'extensions\' or \'rewritePaths\'', withProvider, (t, provider) => { + validateConfig(t, provider, {foo: 1}); +}); + +test('main() config validation: throw when config.extensions contains empty strings', withProvider, (t, provider) => { + validateConfig(t, provider, {extensions: ['']}); +}); + +test('main() config validation: throw when config.extensions contains non-strings', withProvider, (t, provider) => { + validateConfig(t, provider, {extensions: [1]}); +}); + +test('main() config validation: throw when config.extensions contains duplicates', withProvider, (t, provider) => { + validateConfig(t, provider, {extensions: ['ts', 'ts']}); +}); + +test('main() config validation: config may not be an empty object', withProvider, (t, provider) => { + validateConfig(t, provider, {}); +}); + +test('main() config validation: rewrite paths must end in a /', withProvider, (t, provider) => { + validateConfig(t, provider, {rewritePaths: {src: 'build/'}}); + validateConfig(t, provider, {rewritePaths: {'src/': 'build'}}); +}); + +test('main() extensions: defaults to [\'ts\']', withProvider, (t, provider) => { + t.deepEqual(provider.main({config: {rewritePaths: {'src/': 'build/'}}}).extensions, ['ts']); +}); + +test('main() extensions: returns configured extensions', withProvider, (t, provider) => { + const extensions = ['tsx']; + t.deepEqual(provider.main({config: {extensions, rewritePaths: {'src/': 'build/'}}}).extensions, extensions); +}); + +test('main() extensions: always returns new arrays', withProvider, (t, provider) => { + const main = provider.main({config: {rewritePaths: {'src/': 'build/'}}}); + t.not(main.extensions, main.extensions); +}); + test('main() ignoreChange()', withProvider, (t, provider) => { const main = provider.main({config: {rewritePaths: {'src/': 'build/'}}}); t.true(main.ignoreChange(path.join(__dirname, 'src/foo.ts'))); @@ -41,3 +94,29 @@ test('main() updateGlobs()', withProvider, (t, provider) => { ignoredByWatcherPatterns: ['assets/**'] })); }); + +const compile = async provider => { + return { + state: await provider.main({ + config: { + rewritePaths: { + 'typescript/': 'fixtures/' + } + } + }).compile() + }; +}; + +test('worker(): load rewritten paths files', withProvider, async (t, provider) => { + const {state} = await compile(provider); + const {stdout, stderr} = await execa.node( + path.join(__dirname, 'fixtures/install-and-load'), + ['ava-3', JSON.stringify(state), path.join(__dirname, 'typescript', 'file.ts')], + {cwd: path.join(__dirname, 'fixtures')} + ); + if (stderr.length > 0) { + t.log(stderr); + } + + t.snapshot(stdout); +}); diff --git a/test/protocol-ava-3.js b/test/protocol-ava-3.js deleted file mode 100644 index 5839f6e..0000000 --- a/test/protocol-ava-3.js +++ /dev/null @@ -1,101 +0,0 @@ -const path = require('path'); -const test = require('ava'); -const execa = require('execa'); -const pkg = require('../package.json'); -const makeProvider = require('..'); - -const withProvider = (t, run) => run(t, makeProvider({ - negotiateProtocol(identifiers, {version}) { - t.true(identifiers.includes('ava-3')); - t.is(version, pkg.version); - return { - ava: {version: '3.0.0'}, - identifier: 'ava-3', - normalizeGlobPatterns: patterns => patterns, - async findFiles({patterns}) { - return patterns.map(file => path.join(__dirname, file)); - }, - projectDir: __dirname - }; - } -})); - -const validateConfig = (t, provider, config) => { - const error = t.throws(() => provider.main({config})); - error.message = error.message.replace(`v${pkg.version}`, 'v${pkg.version}'); // eslint-disable-line no-template-curly-in-string - t.snapshot(error); -}; - -test('negotiates ava-3 protocol', withProvider, t => t.plan(2)); - -test('main() config validation: throw when config is not a plain object', withProvider, (t, provider) => { - validateConfig(t, provider, false); - validateConfig(t, provider, true); - validateConfig(t, provider, null); - validateConfig(t, provider, []); -}); - -test('main() config validation: throw when config contains keys other than \'extensions\' or \'rewritePaths\'', withProvider, (t, provider) => { - validateConfig(t, provider, {foo: 1}); -}); - -test('main() config validation: throw when config.extensions contains empty strings', withProvider, (t, provider) => { - validateConfig(t, provider, {extensions: ['']}); -}); - -test('main() config validation: throw when config.extensions contains non-strings', withProvider, (t, provider) => { - validateConfig(t, provider, {extensions: [1]}); -}); - -test('main() config validation: throw when config.extensions contains duplicates', withProvider, (t, provider) => { - validateConfig(t, provider, {extensions: ['ts', 'ts']}); -}); - -test('main() config validation: config may not be an empty object', withProvider, (t, provider) => { - validateConfig(t, provider, {}); -}); - -test('main() config validation: rewrite paths must end in a /', withProvider, (t, provider) => { - validateConfig(t, provider, {rewritePaths: {src: 'build/'}}); - validateConfig(t, provider, {rewritePaths: {'src/': 'build'}}); -}); - -test('main() extensions: defaults to [\'ts\']', withProvider, (t, provider) => { - t.deepEqual(provider.main({config: {rewritePaths: {'src/': 'build/'}}}).extensions, ['ts']); -}); - -test('main() extensions: returns configured extensions', withProvider, (t, provider) => { - const extensions = ['tsx']; - t.deepEqual(provider.main({config: {extensions, rewritePaths: {'src/': 'build/'}}}).extensions, extensions); -}); - -test('main() extensions: always returns new arrays', withProvider, (t, provider) => { - const main = provider.main({config: {rewritePaths: {'src/': 'build/'}}}); - t.not(main.extensions, main.extensions); -}); - -const compile = async provider => { - return { - state: await provider.main({ - config: { - rewritePaths: { - 'typescript/': 'fixtures/' - } - } - }).compile() - }; -}; - -test('worker(): load rewritten paths files', withProvider, async (t, provider) => { - const {state} = await compile(provider); - const {stdout, stderr} = await execa.node( - path.join(__dirname, 'fixtures/install-and-load'), - ['ava-3', JSON.stringify(state), path.join(__dirname, 'typescript', 'file.ts')], - {cwd: path.join(__dirname, 'fixtures')} - ); - if (stderr.length > 0) { - t.log(stderr); - } - - t.snapshot(stdout); -}); diff --git a/test/snapshots/protocol-ava-3.2.js.md b/test/snapshots/protocol-ava-3.2.js.md index 121606e..98cbcff 100644 --- a/test/snapshots/protocol-ava-3.2.js.md +++ b/test/snapshots/protocol-ava-3.2.js.md @@ -4,6 +4,86 @@ The actual snapshot is saved in `protocol-ava-3.2.js.snap`. Generated by [AVA](https://avajs.dev). +## main() config validation: throw when config is not a plain object + +> Snapshot 1 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +> Snapshot 2 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +> Snapshot 3 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +> Snapshot 4 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +## main() config validation: throw when config contains keys other than 'extensions' or 'rewritePaths' + +> Snapshot 1 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +## main() config validation: throw when config.extensions contains empty strings + +> Snapshot 1 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +## main() config validation: throw when config.extensions contains non-strings + +> Snapshot 1 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +## main() config validation: throw when config.extensions contains duplicates + +> Snapshot 1 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +## main() config validation: config may not be an empty object + +> Snapshot 1 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +## main() config validation: rewrite paths must end in a / + +> Snapshot 1 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + +> Snapshot 2 + + Error { + message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', + } + ## main() updateGlobs() > Snapshot 1 @@ -19,3 +99,9 @@ Generated by [AVA](https://avajs.dev). 'build/**/*.js.map', ], } + +## worker(): load rewritten paths files + +> Snapshot 1 + + 'logged in file.js' diff --git a/test/snapshots/protocol-ava-3.2.js.snap b/test/snapshots/protocol-ava-3.2.js.snap index d5b6a0d..b76e02d 100644 Binary files a/test/snapshots/protocol-ava-3.2.js.snap and b/test/snapshots/protocol-ava-3.2.js.snap differ diff --git a/test/snapshots/protocol-ava-3.js.md b/test/snapshots/protocol-ava-3.js.md deleted file mode 100644 index 43ba7b2..0000000 --- a/test/snapshots/protocol-ava-3.js.md +++ /dev/null @@ -1,91 +0,0 @@ -# Snapshot report for `test/protocol-ava-3.js` - -The actual snapshot is saved in `protocol-ava-3.js.snap`. - -Generated by [AVA](https://avajs.dev). - -## main() config validation: config may not be an empty object - -> Snapshot 1 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -## main() config validation: rewrite paths must end in a / - -> Snapshot 1 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -> Snapshot 2 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -## main() config validation: throw when config contains keys other than 'extensions' or 'rewritePaths' - -> Snapshot 1 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -## main() config validation: throw when config is not a plain object - -> Snapshot 1 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -> Snapshot 2 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -> Snapshot 3 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -> Snapshot 4 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -## main() config validation: throw when config.extensions contains duplicates - -> Snapshot 1 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -## main() config validation: throw when config.extensions contains empty strings - -> Snapshot 1 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -## main() config validation: throw when config.extensions contains non-strings - -> Snapshot 1 - - Error { - message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.', - } - -## worker(): load rewritten paths files - -> Snapshot 1 - - 'logged in file.js' diff --git a/test/snapshots/protocol-ava-3.js.snap b/test/snapshots/protocol-ava-3.js.snap deleted file mode 100644 index 35da63a..0000000 Binary files a/test/snapshots/protocol-ava-3.js.snap and /dev/null differ