Skip to content

Commit

Permalink
Merge pull request #2 from halfzebra/0.19-tests
Browse files Browse the repository at this point in the history
0.19 tests
  • Loading branch information
xtian authored Aug 29, 2018
2 parents df02ef6 + f081b57 commit 1e6cb02
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,14 @@ module.exports = function() {
.then(function(results) {
var output = results[results.length - 1]; // compilation output is always last

if (output.kind == 'success') {
if (output.kind === 'success') {
alreadyCompiledFiles.push(resourcePath);
callback(null, output.result);
} else {
if (typeof output.error === 'string') {
output.error = new Error(output.error);
}

output.error.message = 'Compiler process exited with error ' + output.error.message;
callback(output.error);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"elm": "^0.19.0",
"glob": "^7.1.1",
"loader-utils": "^1.0.2",
"node-elm-compiler": "rtfeldman/node-elm-compiler#0.19",
"node-elm-compiler": "^5.0.0",
"yargs": "^6.5.0"
},
"devDependencies": {
Expand Down
17 changes: 0 additions & 17 deletions test/fixtures/elm-package.json

This file was deleted.

26 changes: 26 additions & 0 deletions test/fixtures/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"summary": "Tests for `elm-webpack-loader`.",
"type": "application",
"source-directories": [
".",
"../other_elm_source_dir"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.0",
"elm/core": "1.0.0",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
17 changes: 9 additions & 8 deletions test/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var fixturesDir = path.join(__dirname, 'fixtures');
var badSource = path.join(fixturesDir, 'Bad.elm');
var goodSource = path.join(fixturesDir, 'Good.elm');
var goodDependency = path.join(fixturesDir, 'GoodDependency.elm');
var elmPackage = path.join(fixturesDir, 'elm-package.json');
var elmPackage = path.join(fixturesDir, 'elm.json');
var otherElmSourceDir = path.join(__dirname, 'other_elm_source_dir');

var toString = Object.prototype.toString;
Expand All @@ -22,11 +22,11 @@ var hash = function (data) {
};

var compile = function (filename) {
return compiler.compileToString([filename], {yes: true, cwd: fixturesDir})
return compiler.compileToString([filename], {cwd: fixturesDir})
.then(function (data) {
return data.toString();
});
}
};

// Mock of webpack's loader context.
var mock = function (source, query, opts, callback, watchMode, cwd) {
Expand Down Expand Up @@ -154,8 +154,9 @@ describe('async mode', function () {
foo: 'bar'
};

var callback = function () {
assert.match(context.emittedWarning(), /unknown Elm compiler option/i);
var callback = function (err) {
assert.isPrototypeOf(err, Error);
assert.match(err.message, /unknown Elm compiler option/i);
done();
};

Expand All @@ -180,13 +181,13 @@ describe('async mode', function () {
loader.call(context, goodSource);
});

xit('emits errors for incorrect source files', function (done) {
it('emits errors for incorrect source files', function (done) {
var options = {
cwd: fixturesDir
};

var callback = function () {
assert.match(context.emittedError(), /syntax problem/i);
var callback = function (err) {
assert.match(err.message, /parse error/i);
done();
};

Expand Down

0 comments on commit 1e6cb02

Please sign in to comment.