Skip to content

Commit 226ba5f

Browse files
committed
imrpovements
1 parent 536b489 commit 226ba5f

7 files changed

+41
-19
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ Then, enable TypeScript support either in `package.json` or `ava.config.*`:
2424
"typescript": {
2525
"rewritePaths": {
2626
"src/": "build/"
27-
}
27+
},
28+
"compile": true
2829
}
2930
}
3031
}
3132
```
3233

33-
Both keys and values of the `rewritePaths` object must end with a `/`. Paths are relative to your project directory.
34+
Both keys and values of the `rewritePaths` object must end with a `/`. Paths are relative to your project directory.\
35+
You can enable compilation via the `compile` property. It is recommended to set it to `false` when running `ts` in a watcher mode.
3436

3537
Output files are expected to have the `.js` extension.
3638

index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ const execa = require('execa');
66

77
const pkg = require('./package.json');
88

9-
function isPlainObject(x) {
10-
return x !== null && typeof x === 'object' && Reflect.getPrototypeOf(x) === Object.prototype;
11-
}
12-
139
function isValidExtensions(extensions) {
1410
return Array.isArray(extensions) &&
1511
extensions.length > 0 &&
@@ -28,11 +24,11 @@ function isValidRewritePaths(rewritePaths) {
2824
}
2925

3026
function isValidCompile(compile) {
31-
return typeof compile === 'boolean' || compile === undefined;
27+
return typeof compile === 'boolean';
3228
}
3329

3430
async function compileTypeScript(projectDir) {
35-
return execa('tsc', ['--build', path.resolve(projectDir, 'tsconfig.json'), '--incremental'], {preferLocal: true, cwd: projectDir});
31+
return execa('tsc', ['--incremental'], {preferLocal: true, cwd: projectDir});
3632
}
3733

3834
module.exports = ({negotiateProtocol}) => {

test/compilation.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const compile = async provider => {
1515
rewritePaths: {
1616
'typescript/': 'fixtures/',
1717
'compiled/': 'fixtures/compiled/'
18-
}
18+
},
19+
compile: true
1920
}
2021
}).compile()
2122
};

test/protocol-ava-3.2.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ const withProvider = require('./_with-provider');
55
test('negotiates ava-3.2 protocol', withProvider, t => t.plan(2));
66

77
test('main() ignoreChange()', withProvider, (t, provider) => {
8-
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}}});
8+
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
99
t.true(main.ignoreChange(path.join(__dirname, 'src/foo.ts')));
1010
t.false(main.ignoreChange(path.join(__dirname, 'build/foo.js')));
1111
});
1212

1313
test('main() resolveTestfile()', withProvider, (t, provider) => {
14-
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}}});
14+
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
1515
t.is(main.resolveTestFile(path.join(__dirname, 'src/foo.ts')), path.join(__dirname, 'build/foo.js'));
1616
t.is(main.resolveTestFile(path.join(__dirname, 'build/foo.js')), path.join(__dirname, 'build/foo.js'));
1717
t.is(main.resolveTestFile(path.join(__dirname, 'foo/bar.ts')), path.join(__dirname, 'foo/bar.ts'));
1818
});
1919

2020
test('main() updateGlobs()', withProvider, (t, provider) => {
21-
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}}});
21+
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
2222
t.snapshot(main.updateGlobs({
2323
filePatterns: ['src/test.ts'],
2424
ignoredByWatcherPatterns: ['assets/**']

test/protocol-ava-3.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('main() config validation: throw when config is not a plain object', withPr
1717
validateConfig(t, provider, []);
1818
});
1919

20-
test('main() config validation: throw when config contains keys other than \'extensions\' or \'rewritePaths\'', withProvider, (t, provider) => {
20+
test('main() config validation: throw when config contains keys other than \'extensions\', \'rewritePaths\' or \'compile\'', withProvider, (t, provider) => {
2121
validateConfig(t, provider, {foo: 1});
2222
});
2323

@@ -37,25 +37,26 @@ test('main() config validation: config may not be an empty object', withProvider
3737
validateConfig(t, provider, {});
3838
});
3939

40-
test('main() config validation: throw when config.compile is not a boolean nor undefined', withProvider, (t, provider) => {
40+
test('main() config validation: throw when config.compile is not a boolean', withProvider, (t, provider) => {
4141
validateConfig(t, provider, {rewritePaths: {'src/': 'build/'}, compile: 1});
42+
validateConfig(t, provider, {rewritePaths: {'src/': 'build/'}, compile: undefined});
4243
});
4344

4445
test('main() config validation: rewrite paths must end in a /', withProvider, (t, provider) => {
45-
validateConfig(t, provider, {rewritePaths: {src: 'build/'}});
46-
validateConfig(t, provider, {rewritePaths: {'src/': 'build'}});
46+
validateConfig(t, provider, {rewritePaths: {src: 'build/', compile: false}});
47+
validateConfig(t, provider, {rewritePaths: {'src/': 'build', compile: false}});
4748
});
4849

4950
test('main() extensions: defaults to [\'ts\']', withProvider, (t, provider) => {
50-
t.deepEqual(provider.main({config: {rewritePaths: {'src/': 'build/'}}}).extensions, ['ts']);
51+
t.deepEqual(provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}}).extensions, ['ts']);
5152
});
5253

5354
test('main() extensions: returns configured extensions', withProvider, (t, provider) => {
5455
const extensions = ['tsx'];
55-
t.deepEqual(provider.main({config: {extensions, rewritePaths: {'src/': 'build/'}}}).extensions, extensions);
56+
t.deepEqual(provider.main({config: {extensions, rewritePaths: {'src/': 'build/'}, compile: false}}).extensions, extensions);
5657
});
5758

5859
test('main() extensions: always returns new arrays', withProvider, (t, provider) => {
59-
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}}});
60+
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
6061
t.not(main.extensions, main.extensions);
6162
});

test/snapshots/protocol-ava-3.js.md

+22
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,25 @@ Generated by [AVA](https://avajs.dev).
9191
Error {
9292
message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.',
9393
}
94+
95+
## main() config validation: throw when config contains keys other than 'extensions', 'rewritePaths' or 'compile'
96+
97+
> Snapshot 1
98+
99+
Error {
100+
message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.',
101+
}
102+
103+
## main() config validation: throw when config.compile is not a boolean
104+
105+
> Snapshot 1
106+
107+
Error {
108+
message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.',
109+
}
110+
111+
> Snapshot 2
112+
113+
Error {
114+
message: 'Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.',
115+
}

test/snapshots/protocol-ava-3.js.snap

59 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)