Skip to content

Commit

Permalink
Updates and breaking changes
Browse files Browse the repository at this point in the history
* Update minimal Node.js versions

* Update dev dependencies

* Update dependencies

* Remove support for the ava-3 protocol
  • Loading branch information
novemberborn authored Apr 11, 2021
1 parent 96b4ae4 commit de9c6f7
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/.nyc_output
/coverage
/node_modules
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
81 changes: 80 additions & 1 deletion test/protocol-ava-3.2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const test = require('ava');
const execa = require('execa');
const pkg = require('../package.json');
const makeProvider = require('..');

Expand All @@ -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}) {
Expand All @@ -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')));
Expand All @@ -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);
});
101 changes: 0 additions & 101 deletions test/protocol-ava-3.js

This file was deleted.

86 changes: 86 additions & 0 deletions test/snapshots/protocol-ava-3.2.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,3 +99,9 @@ Generated by [AVA](https://avajs.dev).
'build/**/*.js.map',
],
}

## worker(): load rewritten paths files

> Snapshot 1
'logged in file.js'
Binary file modified test/snapshots/protocol-ava-3.2.js.snap
Binary file not shown.
Loading

0 comments on commit de9c6f7

Please sign in to comment.