Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
23629ec
elm-test.js: Organize `require`s
lydell Oct 29, 2020
6f1612f
elm-test.js: Remove dead code
lydell Oct 29, 2020
c13377b
elm-test.js: Remove unnecessary uncaughtException handler
lydell Oct 29, 2020
e4cdcd5
elm-test.js: Replace `var` with `let` and `const`
lydell Oct 29, 2020
e3bd626
elm-test.js: Use arrow functions
lydell Oct 29, 2020
ba9d21d
elm-test.js: Remove unused CLI flag
lydell Oct 29, 2020
5419e73
elm-test.js: WIP Parse CLI arguments in a more structured way
lydell Oct 29, 2020
6572e92
Remove undocumented and rather useless --verbose option
lydell Oct 29, 2020
469482e
Hide compiler Success print
lydell Oct 29, 2020
c7cb303
Fix option parsing
lydell Oct 29, 2020
ed0f4bf
Moving to async/await: lib/Runner.js
chebro Oct 30, 2020
16bbbe6
Moving to async/await: lib/elm-test.js
chebro Oct 30, 2020
27e8b58
Moving to async/await: lib/elm-test.js - Forgot to pass error to catc…
chebro Oct 30, 2020
e7968cc
Moving to async/await: lib/Runner.js - added await keyword
chebro Oct 30, 2020
0963716
Moving to async/await: lib/Runner.js - fixed async on the wrong function
chebro Oct 30, 2020
7f52eba
shifted function calls inside try blocks
chebro Oct 30, 2020
10e60b7
Parse --flag=value
lydell Oct 30, 2020
937827b
Tests
lydell Oct 30, 2020
d735086
Add some type annotations
lydell Oct 30, 2020
3dd8c8a
Remove unnecessary globifyWithRoot function
lydell Oct 30, 2020
62081dc
Type Report
lydell Oct 30, 2020
9ae34c7
Use type for Report everyhere
lydell Oct 30, 2020
8e83f1f
Don’t require elm to exist in PATH to be able to show help
lydell Oct 30, 2020
b30f848
Improve help text
lydell Oct 30, 2020
53e68a1
Improve error messages
lydell Oct 30, 2020
7bd27a7
Convert to async/await where it improves readability
lydell Oct 30, 2020
d56ef96
Reorder functions slightly for better readability
lydell Oct 30, 2020
8b56a06
Various cleanups
lydell Oct 30, 2020
df6d286
Better description for --compiler
lydell Oct 30, 2020
322b832
Show defaults for all options
lydell Oct 30, 2020
d3c3ade
Fix accidentally flipped condition
lydell Oct 31, 2020
dda50af
Better data field for Error
lydell Oct 31, 2020
ab65696
Move flags parsing to its own file
lydell Oct 31, 2020
1c45531
Reorder and better parameter name
lydell Nov 1, 2020
02aa8c2
Exhaustive check switch:es in elm-test.js
lydell Nov 1, 2020
263f671
Add some more type annotations
lydell Nov 1, 2020
bc3599a
Test negative integers
lydell Nov 1, 2020
9199b63
Comment Prettier/Flow shenanigans
lydell Nov 1, 2020
77110d0
Remove defunct Node.js version check
lydell Nov 1, 2020
814e814
Disallow `--watch=some-value`
lydell Nov 1, 2020
ef5b05b
Merge lydell:improve-elm-test.js -> chebro:async-await
chebro Nov 2, 2020
34033e2
Merge pull request #1 from lydell/improve-elm-test.js
chebro Nov 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function findTests(
isPackageProject /*: boolean */
) /*: Promise<Array<{ moduleName: string, possiblyTests: Array<string> }>> */ {
return Promise.all(
testFilePaths.map((filePath) => {
testFilePaths.map(async (filePath) => {
const matchingSourceDirs = sourceDirs.filter((dir) =>
filePath.startsWith(`${dir}${path.sep}`)
);
Expand Down Expand Up @@ -51,12 +51,11 @@ function findTests(
);
}

return Parser.extractExposedPossiblyTests(filePath).then(
(possiblyTests) => ({
moduleName,
possiblyTests,
})
);
const possiblyTests = await Parser.extractExposedPossiblyTests(filePath);
return {
moduleName,
possiblyTests
}
})
);
}
Expand Down
114 changes: 56 additions & 58 deletions lib/elm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ if (args._[0] === 'install') {

let runsExecuted = 0;

function runTests(generatedCodeDir /*: string */, testFile /*: string */) {
async function runTests(generatedCodeDir /*: string */, testFile /*: string */) {
const dest = path.resolve(path.join(generatedCodeDir, 'elmTestOutput.js'));

// Incorporate the process PID into the socket name, so elm-test processes can
Expand All @@ -205,32 +205,29 @@ function runTests(generatedCodeDir /*: string */, testFile /*: string */) {
? '\\\\.\\pipe\\elm_test-' + process.pid + '-' + runsExecuted
: '/tmp/elm_test-' + process.pid + '.sock';

return Compile.compile(
await Compile.compile(
testFile,
dest,
args.verbose,
pathToElmBinary,
args.report
)
.then(function () {
return Generate.prepareCompiledJsFile(pipeFilename, dest).then(
function () {
return Supervisor.run(
packageInfo.version,
pipeFilename,
report,
processes,
dest,
args.watch,
Compile.isMachineReadableReporter(report)
);
}
);
})
.catch(function (error) {
await Generate.prepareCompiledJsFile(pipeFilename, dest)
try {
Comment thread
chebro marked this conversation as resolved.
Outdated
return Supervisor.run(
packageInfo.version,
pipeFilename,
report,
processes,
dest,
args.watch,
Compile.isMachineReadableReporter(report)
);
}
catch (error) {
console.error('Compilation failed for', testFile);
return Promise.reject(error);
});
}
}

function globify(filename) {
Expand Down Expand Up @@ -333,19 +330,22 @@ if (isMake) {
projectElmJson
);

Compile.compileSources(
testFilePaths,
generatedCodeDir,
args.verbose,
pathToElmBinary,
args.report
)
.then(function () {
process.exit(0);
})
.catch(function () {
process.exit(1);
});
(async () => {
await Compile.compileSources(
testFilePaths,
generatedCodeDir,
args.verbose,
pathToElmBinary,
args.report
)
try {
Comment thread
chebro marked this conversation as resolved.
Outdated
process.exit(0);
}
catch {
process.exit(1);
}
})();

} else {
if (testFilePaths.length === 0) {
console.error(noFilesFoundError(testFileGlobs));
Expand All @@ -360,35 +360,33 @@ if (isMake) {
projectElmJson
);

function run() {
async function run() {
// This compiles all the tests so that we generate *.elmi files for them,
// which we can then read to determine which tests need to be run.
return Runner.findTests(testFilePaths, sourceDirs, isPackageProject)
.then(function (testModules) {
process.chdir(generatedCodeDir);

const mainFile = Generate.generateMainModule(
parseInt(args.fuzz),
parseInt(args.seed),
args.report,
testFileGlobs,
testFilePaths,
testModules,
generatedSrc,
processes
);
const testModules = await Runner.findTests(testFilePaths, sourceDirs, isPackageProject)
try {
Comment thread
chebro marked this conversation as resolved.
Outdated
process.chdir(generatedCodeDir);

const mainFile = Generate.generateMainModule(
parseInt(args.fuzz),
parseInt(args.seed),
args.report,
testFileGlobs,
testFilePaths,
testModules,
generatedSrc,
processes
);

return runTests(generatedCodeDir, mainFile);
})
.catch(function (err) {
console.error(err.message);
if (!args.watch) {
process.exit(1);
}
})
.then(function () {
console.log(chalk.blue('Watching for changes...'));
});
return runTests(generatedCodeDir, mainFile);
}
catch (err) {
console.error(err.message);
if (!args.watch) {
process.exit(1);
}
}
console.log(chalk.blue('Watching for changes...'));
}

var currentRun = run();
Expand Down