-
Notifications
You must be signed in to change notification settings - Fork 82
Fix watch for packages when there are compilation errors in src/ #453
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,9 +230,9 @@ function runTests(generatedCodeDir /*: string */, testFile /*: string */) { | |
| } | ||
| ); | ||
| }) | ||
| .catch(function (exitCode) { | ||
| .catch(function (error) { | ||
| console.error('Compilation failed for', testFile); | ||
| return Promise.reject(exitCode); | ||
| return Promise.reject(error); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -281,7 +281,6 @@ function getGlobsToWatch(elmJson) { | |
| }); | ||
| } | ||
|
|
||
| let projectElmJson = {}; | ||
| let report; | ||
|
|
||
| if ( | ||
|
|
@@ -305,77 +304,53 @@ function infoLog(msg) { | |
| } | ||
| } | ||
|
|
||
| // It's important to globify all the arguments. | ||
| // On Bash 4.x (or zsh), if you give it a glob as its last argument, Bash | ||
| // translates that into a list of file paths. On bash 3.x it's just a string. | ||
| // Ergo, globify all the arguments we receive. | ||
| const isMake = args._[0] === 'make'; | ||
| const testFileGlobs = isMake ? args._.slice(1) : args._; | ||
| const testFilePaths = resolveGlobs(testFileGlobs); | ||
| const projectRootDir = process.cwd(); | ||
| const generatedCodeDir = Compile.getGeneratedCodeDir(projectRootDir); | ||
| const hasBeenGivenCustomGlobs = testFileGlobs.length > 0; | ||
|
|
||
| if (args._[0] === 'make') { | ||
| const files = args._.slice(1); | ||
| const elmJsonPath = path.resolve(path.join(projectRootDir, 'elm.json')); | ||
| let projectElmJson; | ||
|
|
||
| // It's important to globify all the arguments. | ||
| // On Bash 4.x (or zsh), if you give it a glob as its last argument, Bash | ||
| // translates that into a list of file paths. On bash 3.x it's just a string. | ||
| // Ergo, globify all the arguments we receive. | ||
| const fileGlobs = files.length > 0 ? files : []; | ||
| const testFilePaths = resolveGlobs(files); | ||
| const hasBeenGivenCustomGlobs = fileGlobs.length > 0; | ||
| const elmJsonPath = path.resolve(path.join(projectRootDir, 'elm.json')); | ||
| try { | ||
| projectElmJson = fs.readJsonSync(elmJsonPath); | ||
| } catch (err) { | ||
| console.error('Error reading elm.json: ' + err.message); | ||
| throw process.exit(1); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to crash if we are in watch mode and the project elm json is invalid?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And what happens if someone edits their elm.json while we are watching tests>
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn’t think about that case! This could for sure be a future enhancement. Currently this is done outside of the watch loop so it would require more changes than I’m comfortable with at the moment. This looks like added code but it’s in fact just moved so were keeping the same behavior as before regarding elm.json at least. Currently, if elm.json changes while the tests run those changes are just ignored.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this PR
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good catch, didn’t think about that change. I’ll have to investigate.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out
My conclusion is:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good enough for me! |
||
| } | ||
|
|
||
| try { | ||
| projectElmJson = fs.readJsonSync(elmJsonPath); | ||
| } catch (err) { | ||
| console.error('Error reading elm.json: ' + err); | ||
| process.exit(1); | ||
| } | ||
| const isPackageProject = projectElmJson.type === 'package'; | ||
|
|
||
| const isPackageProject = projectElmJson.type === 'package'; | ||
| if (isMake) { | ||
| Generate.generateElmJson( | ||
| projectRootDir, | ||
| generatedCodeDir, | ||
| hasBeenGivenCustomGlobs, | ||
| elmJsonPath, | ||
| projectElmJson | ||
| ); | ||
|
|
||
| if (isPackageProject) { | ||
| // Run `elm make` on the project root, to generate the .elmi files. | ||
| Compile.compileSources( | ||
| [], | ||
| projectRootDir, | ||
| args.verbose, | ||
| pathToElmBinary, | ||
| args.report | ||
| ) | ||
| .then(() => | ||
| elmTestMake( | ||
| projectRootDir, | ||
| pathToElmBinary, | ||
| testFilePaths, | ||
| hasBeenGivenCustomGlobs | ||
| ) | ||
| ) | ||
| .catch((err) => { | ||
| console.error(err.message); | ||
| process.exit(1); | ||
| }); | ||
| } else { | ||
| elmTestMake( | ||
| projectRootDir, | ||
| pathToElmBinary, | ||
| testFilePaths, | ||
| hasBeenGivenCustomGlobs | ||
| ); | ||
| } | ||
| Compile.compileAll( | ||
| elmVersion, | ||
| testFilePaths, | ||
| generatedCodeDir, | ||
| args.verbose, | ||
| pathToElmBinary, | ||
| args.report | ||
| ) | ||
| .then(function () { | ||
| process.exit(0); | ||
| }) | ||
| .catch(function () { | ||
| process.exit(1); | ||
| }); | ||
| } else { | ||
| // It's important to globify all the arguments. | ||
| // On Bash 4.x (or zsh), if you give it a glob as its last argument, Bash | ||
| // translates that into a list of file paths. On bash 3.x it's just a string. | ||
| // Ergo, globify all the arguments we receive. | ||
| const testFileGlobs = args._.length > 0 ? args._ : []; | ||
| const testFilePaths = resolveGlobs(testFileGlobs); | ||
|
|
||
| const elmJsonPath = path.resolve(path.join(projectRootDir, 'elm.json')); | ||
|
|
||
| try { | ||
| projectElmJson = fs.readJsonSync(elmJsonPath); | ||
| } catch (err) { | ||
| console.error('Error reading elm.json: ' + err); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const isPackageProject = projectElmJson.type === 'package'; | ||
|
|
||
| if (testFilePaths.length === 0) { | ||
| var extraAppError = | ||
| "\n\nAlternatively, if your application has tests in a different directory, try calling elm-test with a glob: elm-test 'frontend-app/**/*Tests.elm'."; | ||
|
|
@@ -392,37 +367,12 @@ if (args._[0] === 'make') { | |
| process.exit(1); | ||
| } | ||
|
|
||
| if (isPackageProject) { | ||
| // Run `elm make` on the project root, to generate the .elmi files. | ||
| Compile.compileSources( | ||
| [], | ||
| projectRootDir, | ||
| args.verbose, | ||
| pathToElmBinary, | ||
| args.report | ||
| ) | ||
| .then(() => generateAndRun(projectRootDir, testFileGlobs, testFilePaths)) | ||
| .catch((err) => { | ||
| console.error(err.message); | ||
| process.exit(1); | ||
| }); | ||
| } else { | ||
| generateAndRun(projectRootDir, testFileGlobs, testFilePaths); | ||
| } | ||
| } | ||
|
|
||
| function generateAndRun( | ||
| projectRootDir /*: string */, | ||
| testFileGlobs /* Array<string> */, | ||
| testFilePaths /*: Array<string> */ | ||
| ) { | ||
| const generatedCodeDir = Compile.getGeneratedCodeDir(projectRootDir); | ||
| const hasBeenGivenCustomGlobs = testFileGlobs.length > 0; | ||
|
|
||
| const returnValues = Generate.generateElmJson( | ||
| projectRootDir, | ||
| generatedCodeDir, | ||
| hasBeenGivenCustomGlobs | ||
| hasBeenGivenCustomGlobs, | ||
| elmJsonPath, | ||
| projectElmJson | ||
| ); | ||
| const generatedSrc = returnValues[1]; | ||
|
|
||
|
|
@@ -438,27 +388,20 @@ function generateAndRun( | |
| args.report | ||
| ) | ||
| .then(function (testModules) { | ||
| return Promise.resolve() | ||
| .then(function () { | ||
| 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); | ||
| process.exit(1); | ||
| }); | ||
| 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); | ||
|
|
@@ -505,33 +448,3 @@ function generateAndRun( | |
| }); | ||
| } | ||
| } | ||
|
|
||
| function elmTestMake( | ||
| projectRootDir /*: string */, | ||
| pathToElmBinary /*: string */, | ||
| testFilePaths /*: Array<string> */, | ||
| hasBeenGivenCustomGlobs /*: boolean */ | ||
| ) { | ||
| const generatedCodeDir = Compile.getGeneratedCodeDir(projectRootDir); | ||
|
|
||
| Generate.generateElmJson( | ||
| projectRootDir, | ||
| generatedCodeDir, | ||
| hasBeenGivenCustomGlobs | ||
| ); | ||
|
|
||
| Compile.compileAll( | ||
| elmVersion, | ||
| testFilePaths, | ||
| generatedCodeDir, | ||
| args.verbose, | ||
| pathToElmBinary, | ||
| args.report | ||
| ) | ||
| .then(function () { | ||
| process.exit(0); | ||
| }) | ||
| .catch(function () { | ||
| process.exit(1); | ||
| }); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old error was super verbose and not useful when the nice error from
elm makeis printed just above anyway.