-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support compilation using `tsc` before AVA runs tests. This is a breaking change. To retain the old behavior you must configure `compile: false`. Co-authored-by: Mark Wubben <[email protected]>
- Loading branch information
1 parent
de9c6f7
commit 869760a
Showing
18 changed files
with
264 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ insert_final_newline = true | |
[*.yml] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[package.json] | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/coverage | ||
/node_modules | ||
/test/fixtures/typescript/compiled | ||
/test/broken-fixtures/typescript/compiled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const path = require('path'); | ||
const pkg = require('../package.json'); | ||
const makeProvider = require('..'); | ||
|
||
const createProviderMacro = (identifier, avaVersion, projectDir = __dirname) => { | ||
return (t, run) => run(t, makeProvider({ | ||
negotiateProtocol(identifiers, {version}) { | ||
t.true(identifiers.includes(identifier)); | ||
t.is(version, pkg.version); | ||
return { | ||
ava: {avaVersion}, | ||
identifier, | ||
normalizeGlobPatterns: patterns => patterns, | ||
async findFiles({patterns}) { | ||
return patterns.map(file => path.join(projectDir, file)); | ||
}, | ||
projectDir | ||
}; | ||
} | ||
})); | ||
}; | ||
|
||
module.exports = createProviderMacro; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "typescript/compiled" | ||
}, | ||
"include": [ | ||
"typescript" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const path = require('path'); | ||
const test = require('ava'); | ||
const del = require('del'); | ||
const execa = require('execa'); | ||
const createProviderMacro = require('./_with-provider'); | ||
|
||
const withProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'fixtures')); | ||
const withAltProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'broken-fixtures')); | ||
|
||
test.before('deleting compiled files', async t => { | ||
t.log(await del('test/fixtures/typescript/compiled')); | ||
t.log(await del('test/broken-fixtures/typescript/compiled')); | ||
}); | ||
|
||
const compile = async provider => { | ||
return { | ||
state: await provider.main({ | ||
config: { | ||
rewritePaths: { | ||
'ts/': 'typescript/', | ||
'compiled/': 'typescript/compiled/' | ||
}, | ||
compile: 'tsc' | ||
} | ||
}).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'), | ||
[JSON.stringify(state), path.join(__dirname, 'fixtures/ts', 'file.ts')], | ||
{cwd: path.join(__dirname, 'fixtures')} | ||
); | ||
if (stderr.length > 0) { | ||
t.log(stderr); | ||
} | ||
|
||
t.snapshot(stdout); | ||
}); | ||
|
||
test('worker(): runs compiled files', withProvider, async (t, provider) => { | ||
const {state} = await compile(provider); | ||
const {stdout, stderr} = await execa.node( | ||
path.join(__dirname, 'fixtures/install-and-load'), | ||
[JSON.stringify(state), path.join(__dirname, 'fixtures/compiled', 'index.ts')], | ||
{cwd: path.join(__dirname, 'fixtures')} | ||
); | ||
if (stderr.length > 0) { | ||
t.log(stderr); | ||
} | ||
|
||
t.snapshot(stdout); | ||
}); | ||
|
||
test('compile() error', withAltProvider, async (t, provider) => { | ||
const {message} = await t.throwsAsync(compile(provider)); | ||
|
||
t.snapshot(message); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "typescript/compiled" | ||
}, | ||
"include": [ | ||
"typescript" | ||
] | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('logged in fixtures/typescript/index.ts'); |
Oops, something went wrong.