Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak globs depending on compile configuration #39

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions index.js
Expand Up @@ -88,6 +88,8 @@ export default function typescriptProvider({negotiateProtocol}) {
compile,
} = config;

const compilerEnabled = compile === 'tsc';

const rewritePaths = Object.entries(relativeRewritePaths).map(([from, to]) => [
path.join(protocol.projectDir, from),
path.join(protocol.projectDir, to),
Expand All @@ -96,7 +98,7 @@ export default function typescriptProvider({negotiateProtocol}) {

return {
async compile() {
if (compile === 'tsc') {
if (compilerEnabled) {
await compileTypeScript(protocol.projectDir);
}

Expand All @@ -115,7 +117,7 @@ export default function typescriptProvider({negotiateProtocol}) {
return false;
}

return rewritePaths.some(([from]) => filePath.startsWith(from));
return rewritePaths.some(([from, to]) => filePath.startsWith(compilerEnabled ? to : from));
},

resolveTestFile(testfile) {
Expand Down Expand Up @@ -143,6 +145,7 @@ export default function typescriptProvider({negotiateProtocol}) {
ignoredByWatcherPatterns: [
...ignoredByWatcherPatterns,
...Object.values(relativeRewritePaths).map(to => `${to}**/*.js.map`),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd want to keep this, it's useful if the pre-compilation step outputs source maps. And it should be harmless in case we run tsc ourselves.

...Object.entries(relativeRewritePaths).map(([from, to]) => `${compilerEnabled ? to : from}**`),
],
};
},
Expand Down
18 changes: 16 additions & 2 deletions test/protocol-ava-3.2.js
Expand Up @@ -67,23 +67,37 @@ test('main() extensions: always returns new arrays', withProvider, (t, provider)
t.not(main.extensions, main.extensions);
});

test('main() ignoreChange()', withProvider, (t, provider) => {
test('main() ignoreChange() without compilation', withProvider, (t, provider) => {
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
t.true(main.ignoreChange(path.join(__dirname, 'src/foo.ts')));
t.false(main.ignoreChange(path.join(__dirname, 'build/foo.js')));
});

test('main() ignoreChange() with compilation', withProvider, (t, provider) => {
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: 'tsc'}});
t.false(main.ignoreChange(path.join(__dirname, 'src/foo.ts')));
t.false(main.ignoreChange(path.join(__dirname, 'build/foo.js')));
});

test('main() resolveTestfile()', withProvider, (t, provider) => {
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
t.is(main.resolveTestFile(path.join(__dirname, 'src/foo.ts')), path.join(__dirname, 'build/foo.js'));
t.is(main.resolveTestFile(path.join(__dirname, 'build/foo.js')), path.join(__dirname, 'build/foo.js'));
t.is(main.resolveTestFile(path.join(__dirname, 'foo/bar.ts')), path.join(__dirname, 'foo/bar.ts'));
});

test('main() updateGlobs()', withProvider, (t, provider) => {
test('main() updateGlobs() without compilation', withProvider, (t, provider) => {
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
t.snapshot(main.updateGlobs({
filePatterns: ['src/test.ts'],
ignoredByWatcherPatterns: ['assets/**'],
}));
});

test('main() updateGlobs() with compilation', withProvider, (t, provider) => {
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: 'tsc'}});
t.snapshot(main.updateGlobs({
filePatterns: ['src/test.ts'],
ignoredByWatcherPatterns: ['assets/**'],
}));
});
20 changes: 19 additions & 1 deletion test/snapshots/protocol-ava-3.2.js.md
Expand Up @@ -98,7 +98,7 @@ Generated by [AVA](https://avajs.dev).
message: 'Missing \'compile\' property in TypeScript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md',
}

## main() updateGlobs()
## main() updateGlobs() without compilation

> Snapshot 1

Expand All @@ -111,5 +111,23 @@ Generated by [AVA](https://avajs.dev).
ignoredByWatcherPatterns: [
'assets/**',
'build/**/*.js.map',
'src/**',
],
}

## main() updateGlobs() with compilation

> Snapshot 1

{
filePatterns: [
'src/test.ts',
'!**/*.d.ts',
'!build/**',
],
ignoredByWatcherPatterns: [
'assets/**',
'build/**/*.js.map',
'build/**',
],
}
Binary file modified test/snapshots/protocol-ava-3.2.js.snap
Binary file not shown.