Skip to content

Commit

Permalink
Merge pull request #182 from inikulin/gh166
Browse files Browse the repository at this point in the history
Die gracefully on legacy compiler errors (fixes #166)
  • Loading branch information
VasilyStrelyaev committed Nov 13, 2015
2 parents 72e87cc + 6b77000 commit 7a7683d
Show file tree
Hide file tree
Showing 22 changed files with 413 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/compiler/old/**/*.js
src/compiler/legacy/**/*.js
test/server/data/test-suite/**/*.js
7 changes: 1 addition & 6 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ function exit (code) {
}

function error (err) {
var msg = err.message
.split(/\n/g)
.map(line => chalk.red('ERROR ') + line)
.join('\n');

spinner.hide();

console.error(msg);
console.error(chalk.red('ERROR ') + err.message);
console.error(chalk.gray('Type "tescafe -h" for help.'));

exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/client/runner/api/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import COMPILER_CONST from '../../../compiler/old/const';
import COMPILER_CONST from '../../../compiler/legacy/const';
import hammerhead from '../deps/hammerhead';
import testCafeCore from '../deps/testcafe-core';
import * as automation from '../automation/automation';
Expand Down
2 changes: 1 addition & 1 deletion src/client/runner/api/assertions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import COMPILER_CONST from '../../../compiler/old/const';
import COMPILER_CONST from '../../../compiler/legacy/const';
import hammerhead from '../deps/hammerhead';
import testCafeCore from '../deps/testcafe-core';
import * as sourceIndexTracker from '../source-index';
Expand Down
25 changes: 15 additions & 10 deletions src/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import OS from 'os-family';
import { createHash } from 'crypto';
import { resolve as resolveUrl } from 'url';
import { Promise } from 'es6-promise';
import { Compiler as OldCompiler } from './old';
import { Compiler as LegacyCompiler, getErrMsg } from './legacy';
import promisify from 'es6-promisify';
import RequireReader from './require-reader';

Expand All @@ -15,7 +15,7 @@ function exists (filePath) {
return new Promise(resolve => fs.exists(filePath, resolve));
}

export default class Compiler {
export default class LegacyCompilerAdapter {
constructor (sources) {
this.sources = sources;

Expand Down Expand Up @@ -72,7 +72,7 @@ export default class Compiler {
var data = await readFile(cfgPath);
var cfg = JSON.parse(data);

Compiler._resolveConfigModules(cfg, dir);
LegacyCompilerAdapter._resolveConfigModules(cfg, dir);
cfgs.push(cfg);
}
}
Expand All @@ -95,7 +95,7 @@ export default class Compiler {
cfg = cachedCfg;
else {
// NOTE: walk up in the directories hierarchy and collect test_config.json files
var dirConfigs = await Compiler._collectDirConfigs(dirName);
var dirConfigs = await LegacyCompilerAdapter._collectDirConfigs(dirName);

cfg = {
modules: {},
Expand All @@ -119,13 +119,18 @@ export default class Compiler {
return cfg;
}

_createOldCompilerPromise (filePath, modules) {
_createLegacyCompilerPromise (filePath, modules) {
return new Promise((resolve, reject) => {
var oldCompiler = new OldCompiler(filePath, modules, this.requireReader, this.cache.sourceIndex);
var legacyCompiler = new LegacyCompiler(filePath, modules, this.requireReader, this.cache.sourceIndex);

oldCompiler.compile((errs, out) => {
if (errs)
reject(errs);
legacyCompiler.compile((errs, out) => {
if (errs) {
var msg = 'There are test compilation errors:\n';

msg += errs.map(err => ` * ${getErrMsg(err)}`).join('\n');

reject(new Error(msg));
}
else
resolve(out);
});
Expand Down Expand Up @@ -156,7 +161,7 @@ export default class Compiler {
async _compileFile (filePath) {
var { modules, baseUrl } = await this._getConfig(filePath);

var compiled = await this._createOldCompilerPromise(filePath, modules);
var compiled = await this._createLegacyCompilerPromise(filePath, modules);

//NOTE: solve memory overuse issue by storing requireJs in the suite-level hash-based map
//(see: B237609 - Fixture file compiler memory overuse)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7a7683d

Please sign in to comment.