Skip to content

Commit

Permalink
Numerous bug fixes (closes #636, closes #637, closes #635), bump vers…
Browse files Browse the repository at this point in the history
…ion (#638)

* Make es-next compiler filter less restrictive (fixes #636). Force test files to use testcafe version of babel-runtime (fixes #637)

* Report fixtureStart event to reporter plugin for fixtures that declared in the same file (fixes #635)

* Bump version

* Fix regenerator test for node 10
  • Loading branch information
inikulin authored and AlexanderMoskovkin committed Jul 4, 2016
1 parent 06f0326 commit f0fc6ba
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 42 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testcafe",
"version": "0.0.22-alpha",
"version": "0.0.23-alpha",
"main": "lib/index",
"bin": {
"testcafe": "./bin/testcafe"
Expand Down Expand Up @@ -93,6 +93,7 @@
"multer": "^1.1.0",
"opn": "^3.0.3",
"publish-please": "^2.1.3",
"recursive-copy": "^2.0.5",
"request": "^2.58.0",
"saucelabs-connector": "^0.1.3",
"serve-static": "^1.10.0",
Expand Down Expand Up @@ -177,6 +178,7 @@
"multer",
"opn",
"publish-please",
"recursive-copy",
"request",
"saucelabs-connector",
"serve-static",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/es-next/compile-client-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import MESSAGE from '../../errors/runtime/message';
const ANONYMOUS_FN_RE = /^function\*?\s*\(/;
const USE_STRICT_RE = /^('|")use strict('|");?/;
const TRAILING_SEMICOLON_RE = /;\s*$/;
const REGENERATOR_FOOTPRINTS_RE = /(_regenerator(\d+).default|regeneratorRuntime).wrap\(function _callee\$\(_context\)/;
const REGENERATOR_FOOTPRINTS_RE = /(_index\d+\.default|_regenerator\d+\.default|regeneratorRuntime)\.wrap\(function _callee\$\(_context\)/;
const ASYNC_TO_GENERATOR_OUTPUT_CODE = asyncToGenerator(noop).toString();

var babelArtifactPolyfills = {
Expand Down
52 changes: 31 additions & 21 deletions src/compiler/es-next/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import Globals from '../../api/globals';
import { TestCompilationError, APIError } from '../../errors/runtime';
import stackCleaningHook from '../../errors/stack-cleaning-hook';

const COMMON_API_PATH = join(__dirname, '../../api/common');
const NODE_MODULES_PATH = join(__dirname, '../../../node_modules');
const CWD = process.cwd();
const COMMON_API_PATH = join(__dirname, '../../api/common');
const CWD = process.cwd();

const FIXTURE_RE = /(^|;|\s+)fixture\s*(\(\s*('|").+?\3\s*\)|`.+?`)/;
const TEST_RE = /(^|;|\s+)test\s*(\(\s*('|").+?\3\s*,)/;
const FIXTURE_RE = /(^|;|\s+)fixture\s*(\(.+?\)|`.+?`)/;
const TEST_RE = /(^|;|\s+)test\s*\(.+?,/;
const BABEL_RUNTIME_RE = /^babel-runtime(\\|\/|$)/;

var Module = module.constructor;

Expand All @@ -26,14 +26,9 @@ export default class ESNextCompiler {
}

static _getNodeModulesLookupPath (filename) {
var dir = dirname(filename);
var paths = Module._nodeModulePaths(dir);
var dir = dirname(filename);

// HACK: for npm v2 installations, we need to expose our node_modules,
// so that Module will be able to require babel-runtime.
paths.push(NODE_MODULES_PATH);

return paths;
return Module._nodeModulePaths(dir);
}

static _getBabelOptions (filename) {
Expand All @@ -42,15 +37,30 @@ export default class ESNextCompiler {
var presetES2015 = NODE_VER < 4 ? presetES2015Loose : presetES2015Node4;

return {
presets: [presetStage2, presetES2015],
plugins: [transformRuntime],
filename: filename,
sourceMaps: true,
retainLines: true,
ast: false,
babelrc: false,
highlightCode: false,
resolveModuleSource: source => source === 'testcafe' ? COMMON_API_PATH : source
presets: [presetStage2, presetES2015],
plugins: [transformRuntime],
filename: filename,
sourceMaps: true,
retainLines: true,
ast: false,
babelrc: false,
highlightCode: false,

resolveModuleSource: source => {
if (source === 'testcafe')
return COMMON_API_PATH;

if (BABEL_RUNTIME_RE.test(source)) {
try {
return require.resolve(source);
}
catch (err) {
return source;
}
}

return source;
}
};
}

Expand Down
17 changes: 7 additions & 10 deletions src/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export default class Reporter {

static _createReportItem (test, runsPerTest) {
return {
fixtureName: test.fixture.name,
fixturePath: test.fixture.path,
testName: test.name,
fixture: test.fixture,
test: test,
screenshotPath: null,
pendingRuns: runsPerTest,
errs: [],
Expand All @@ -33,9 +32,7 @@ export default class Reporter {
}

_getReportItemForTestRun (testRun) {
var test = testRun.test;

return find(this.reportQueue, i => i.fixturePath === test.fixture.path && i.testName === test.name);
return find(this.reportQueue, i => i.test === testRun.test);
}

_shiftReportQueue () {
Expand All @@ -51,15 +48,15 @@ export default class Reporter {

reportItem.errs = sortBy(reportItem.errs, ['userAgent', 'type']);

this.plugin.reportTestDone(reportItem.testName, reportItem.errs, durationMs, reportItem.unstable, reportItem.screenshotPath);
this.plugin.reportTestDone(reportItem.test.name, reportItem.errs, durationMs, reportItem.unstable, reportItem.screenshotPath);

// NOTE: here we assume that tests are sorted by fixture.
// Therefore, if the next report item has a different
// fixture, we can report this fixture start.
var nextReportItem = this.reportQueue[0];

if (nextReportItem && nextReportItem.fixturePath !== reportItem.fixturePath)
this.plugin.reportFixtureStart(nextReportItem.fixtureName, nextReportItem.fixturePath);
if (nextReportItem && nextReportItem.fixture !== reportItem.fixture)
this.plugin.reportFixtureStart(nextReportItem.fixture.name, nextReportItem.fixture.path);
}

_assignTaskEventHandlers (task) {
Expand All @@ -69,7 +66,7 @@ export default class Reporter {
var first = this.reportQueue[0];

this.plugin.reportTaskStart(startTime, userAgents, this.testCount);
this.plugin.reportFixtureStart(first.fixtureName, first.fixturePath);
this.plugin.reportFixtureStart(first.fixture.name, first.fixture.path);
});

task.on('test-run-start', testRun => {
Expand Down
13 changes: 13 additions & 0 deletions test/functional/fixtures/regression/gh-637/data/testfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ClientFunction } from 'testcafe';

const getLocation = ClientFunction(() => document.location.toString());

fixture `Some fixture`;

test('Some test', async t => {
await t.wait(30);

await getLocation();

return Promise.resolve();
});
18 changes: 18 additions & 0 deletions test/functional/fixtures/regression/gh-637/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var tmp = require('tmp');
var path = require('path');
var copy = require('recursive-copy');

describe('[Regression](GH-637)', function () {
it("Should let test file locate babel-runtime if it's not installed on global or test file node_modules lookup scope", function () {
tmp.setGracefulCleanup();

var tmpDir = tmp.dirSync().name;
var srcDir = path.join(__dirname, './data');

return copy(srcDir, tmpDir).then(function () {
var testFile = path.join(tmpDir, './testfile.js');

return runTests(testFile, 'Some test', { only: 'chrome' });
});
});
});
2 changes: 1 addition & 1 deletion test/functional/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ before(function () {
global.runTests = function (fixture, testName, opts) {
var report = '';
var runner = testCafe.createRunner();
var fixturePath = path.join(path.dirname(caller()), fixture);
var fixturePath = path.isAbsolute(fixture) ? fixture : path.join(path.dirname(caller()), fixture);
var skipJsErrors = opts && opts.skipJsErrors;
var quarantineMode = opts && opts.quarantineMode;
var selectorTimeout = opts && opts.selectorTimeout || FUNCTIONAL_TESTS_SELECTOR_TIMEOUT;
Expand Down
4 changes: 3 additions & 1 deletion test/server/data/test-suites/basic/testfile1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ test('Fixture1Test1', async () => {
return `F1T1: ${res}`;
});

test('Fixture1Test2', async () => {
const test2Name = 'Fixture1Test2';

test(test2Name, async () => {
return 'F1T2';
});

Expand Down
4 changes: 3 additions & 1 deletion test/server/data/test-suites/basic/testfile2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ fixture('Fixture3')
.afterEach(() => 'yo')
.beforeEach(() => 'yo');

test('Fixture3Test1', async () => {
const fixture3Name = 'Fixture3Test1';

test(fixture3Name, async () => {
var res = await dep2Fn();

return `F3T1: ${res}`;
Expand Down
12 changes: 6 additions & 6 deletions test/server/reporter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('Reporter', function () {
var fixtureMocks = [
{
name: 'fixture1',
path: './fixture1.js'
path: './file1.js'
},
{
name: 'fixture2',
path: './fixture2.js'
path: './file1.js'
},
{
name: 'fixture3',
path: './fixture3.js'
path: './file2.js'
}
];

Expand Down Expand Up @@ -241,7 +241,7 @@ describe('Reporter', function () {
method: 'reportFixtureStart',
args: [
'fixture1',
'./fixture1.js'
'./file1.js'
]
},
{
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('Reporter', function () {
method: 'reportFixtureStart',
args: [
'fixture2',
'./fixture2.js'
'./file1.js'
]
},
{
Expand All @@ -318,7 +318,7 @@ describe('Reporter', function () {
method: 'reportFixtureStart',
args: [
'fixture3',
'./fixture3.js'
'./file2.js'
]
},
{
Expand Down

0 comments on commit f0fc6ba

Please sign in to comment.