Skip to content

Commit

Permalink
Add comprehensive message for RAW data compiler errors (closes #1302) (
Browse files Browse the repository at this point in the history
…#1303)

* Add comprehensive message for RAW data compiler errors (closes #1302)

* Add test
  • Loading branch information
inikulin authored and AlexanderMoskovkin committed Mar 10, 2017
1 parent d420397 commit a82d506
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ export default class Compiler {
constructor (sources) {
this.sources = sources;
this.esNextCompiler = new EsNextCompiler();
this.rawDataCompiler = new RawFileCompiler();

this.compilers = [
new LegacyCompiler(hammerhead.processScript),
this.esNextCompiler,
this.rawDataCompiler
new RawFileCompiler()
];
}

Expand Down
13 changes: 6 additions & 7 deletions src/compiler/raw-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,18 @@ export default class RawFileCompiler {
}

compile (code, filename) {
var data = null;
var data = null;
var testFile = new TestFile(filename);

try {
data = JSON.parse(code);

data.fixtures.forEach(fixtureSrc => RawFileCompiler._addFixture(testFile, fixtureSrc));

return testFile.getTests();
}
catch (err) {
throw new GeneralError(MESSAGE.cannotParseRawFile, filename, err.toString());
}

var testFile = new TestFile(filename);

data.fixtures.forEach(fixtureSrc => RawFileCompiler._addFixture(testFile, fixtureSrc));

return testFile.getTests();
}
}
17 changes: 14 additions & 3 deletions test/server/compiler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1263,16 +1263,27 @@ describe('Compiler', function () {
});

it('Should raise an error if it cannot parse a raw file', function () {
var testfile = resolve('test/server/data/test-suites/raw/invalid.testcafe');
var testfile1 = resolve('test/server/data/test-suites/raw/invalid.testcafe');
var testfile2 = resolve('test/server/data/test-suites/raw/invalid2.testcafe');

return compile(testfile)
return compile(testfile1)
.then(function () {
throw new Error('Promise rejection is expected');
})
.catch(function (err) {
expect(err.message).contains('Cannot parse a test source file in the raw format at "' + testfile +
expect(err.message).contains('Cannot parse a test source file in the raw format at "' + testfile1 +
'" due to an error.\n\n' +
'SyntaxError: Unexpected token i');
})
.then(function () {
return compile(testfile2);
})
.then(function () {
throw new Error('Promise rejection is expected');
})
.catch(function (err) {
expect(err.message).contains('Cannot parse a test source file in the raw format at "' + testfile2 +
'" due to an error.\n\n');
});
});

Expand Down
7 changes: 7 additions & 0 deletions test/server/data/test-suites/raw/invalid2.testcafe
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"fixtures": [
{
"name": "Hey"
}
]
}

0 comments on commit a82d506

Please sign in to comment.