diff --git a/src/compiler/index.js b/src/compiler/index.js index 75cd57ff89d..85735ff0d39 100644 --- a/src/compiler/index.js +++ b/src/compiler/index.js @@ -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() ]; } diff --git a/src/compiler/raw-file.js b/src/compiler/raw-file.js index 754edc1616c..a2ae99bef5c 100644 --- a/src/compiler/raw-file.js +++ b/src/compiler/raw-file.js @@ -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(); } } diff --git a/test/server/compiler-test.js b/test/server/compiler-test.js index 0faf4dc28fa..dcc9e0e5b67 100644 --- a/test/server/compiler-test.js +++ b/test/server/compiler-test.js @@ -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'); }); }); diff --git a/test/server/data/test-suites/raw/invalid2.testcafe b/test/server/data/test-suites/raw/invalid2.testcafe new file mode 100644 index 00000000000..184e7e2c2fe --- /dev/null +++ b/test/server/data/test-suites/raw/invalid2.testcafe @@ -0,0 +1,7 @@ +{ + "fixtures": [ + { + "name": "Hey" + } + ] +}