diff --git a/index.js b/index.js index ad5983c..f323888 100644 --- a/index.js +++ b/index.js @@ -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), @@ -96,7 +98,7 @@ export default function typescriptProvider({negotiateProtocol}) { return { async compile() { - if (compile === 'tsc') { + if (compilerEnabled) { await compileTypeScript(protocol.projectDir); } @@ -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) { @@ -143,6 +145,7 @@ export default function typescriptProvider({negotiateProtocol}) { ignoredByWatcherPatterns: [ ...ignoredByWatcherPatterns, ...Object.values(relativeRewritePaths).map(to => `${to}**/*.js.map`), + ...Object.entries(relativeRewritePaths).map(([from, to]) => `${compilerEnabled ? to : from}**`), ], }; }, diff --git a/test/protocol-ava-3.2.js b/test/protocol-ava-3.2.js index 83d53cb..932b6e1 100644 --- a/test/protocol-ava-3.2.js +++ b/test/protocol-ava-3.2.js @@ -67,12 +67,18 @@ 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')); @@ -80,10 +86,18 @@ test('main() resolveTestfile()', withProvider, (t, provider) => { 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/**'], + })); +}); diff --git a/test/snapshots/protocol-ava-3.2.js.md b/test/snapshots/protocol-ava-3.2.js.md index 89878f9..9eb75fa 100644 --- a/test/snapshots/protocol-ava-3.2.js.md +++ b/test/snapshots/protocol-ava-3.2.js.md @@ -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 @@ -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/**', ], } diff --git a/test/snapshots/protocol-ava-3.2.js.snap b/test/snapshots/protocol-ava-3.2.js.snap index df5d750..a23ecca 100644 Binary files a/test/snapshots/protocol-ava-3.2.js.snap and b/test/snapshots/protocol-ava-3.2.js.snap differ