-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7580360
commit 823ef86
Showing
12 changed files
with
2,269 additions
and
1,802 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const Base = require('mocha/lib/reporters/base'); | ||
const constants = require('mocha/lib/runner').constants; | ||
const colors = require('colors/safe'); | ||
|
||
class Dot extends Base { | ||
constructor(runner, options) { | ||
super(runner, options); | ||
|
||
runner.on(constants.EVENT_RUN_BEGIN, () => { | ||
process.stdout.write('\n'); | ||
}); | ||
|
||
runner.on(constants.EVENT_TEST_PENDING, test => { | ||
process.stdout.write(colors.yellow('\u00B7')) | ||
}); | ||
|
||
runner.on(constants.EVENT_TEST_PASS, () => { | ||
process.stdout.write(colors.green('\u00B7')); | ||
}); | ||
|
||
runner.on(constants.EVENT_TEST_FAIL, test => { | ||
if (test.duration >= test.timeout()) | ||
process.stdout.write(colors.red('T')); | ||
else | ||
process.stdout.write(colors.red('F')); | ||
}); | ||
|
||
runner.once(constants.EVENT_RUN_END, () => { | ||
process.stdout.write('\n'); | ||
this.epilogue(); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = Dot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const { FixturePool, registerFixture, registerWorkerFixture } = require('../harness/fixturePool'); | ||
const { Test, Suite } = require('mocha'); | ||
const pirates = require('pirates'); | ||
const babel = require('@babel/core'); | ||
const commonSuite = require('mocha/lib/interfaces/common'); | ||
|
||
Error.stackTraceLimit = 15; | ||
global.testOptions = require('../harness/testOptions'); | ||
global.registerFixture = registerFixture; | ||
global.registerWorkerFixture = registerWorkerFixture; | ||
process.env.JEST_WORKER_ID = 1; | ||
|
||
const fixturePool = new FixturePool(); | ||
let revertBabelRequire; | ||
|
||
function fixturesUI(suite) { | ||
const suites = [suite]; | ||
|
||
suite.on(Suite.constants.EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) { | ||
const common = commonSuite(suites, context, mocha); | ||
|
||
context.beforeEach = common.beforeEach; | ||
context.afterEach = common.afterEach; | ||
fixturePool.patchToEnableFixtures(context, 'beforeEach'); | ||
fixturePool.patchToEnableFixtures(context, 'afterEach'); | ||
|
||
context.run = mocha.options.delay && common.runWithSuite(suite); | ||
|
||
context.describe = (title, fn) => { | ||
return common.suite.create({ | ||
title: title, | ||
file: file, | ||
fn: fn | ||
}); | ||
}; | ||
|
||
context.xdescribe = (title, fn) => { | ||
return common.suite.skip({ | ||
title: title, | ||
file: file, | ||
fn: fn | ||
}); | ||
}; | ||
|
||
context.describe.skip = function(condition) { | ||
return condition ? context.xdescribe : context.describe; | ||
}; | ||
|
||
context.describe.only = (title, fn) => { | ||
return common.suite.only({ | ||
title: title, | ||
file: file, | ||
fn: fn | ||
}); | ||
}; | ||
|
||
context.fdescribe = context.describe.only; | ||
|
||
context.it = context.specify = function(title, fn) { | ||
const suite = suites[0]; | ||
if (suite.isPending()) { | ||
fn = null; | ||
} | ||
const wrapped = fixturePool.wrapTestCallback(fn); | ||
const wrapper = wrapped ? (done, ...args) => { | ||
wrapped(...args).then(done).catch(done); | ||
} : undefined; | ||
|
||
const test = new Test(title, wrapper); | ||
test.file = file; | ||
suite.addTest(test); | ||
return test; | ||
}; | ||
|
||
context.it.only = function(title, fn) { | ||
return common.test.only(mocha, context.it(title, fn)); | ||
}; | ||
|
||
context.fit = context.it.only; | ||
|
||
context.xit = function(title) { | ||
return context.it(title); | ||
}; | ||
|
||
context.it.skip = function(condition) { | ||
return condition ? context.xit : context.it; | ||
}; | ||
|
||
context.it.fail = function(condition) { | ||
return condition ? context.xit : context.it; | ||
}; | ||
|
||
context.it.slow = function(condition) { | ||
return context.it; | ||
}; | ||
|
||
context.it.retries = function(n) { | ||
context.retries(n); | ||
}; | ||
|
||
revertBabelRequire = pirates.addHook((code, filename) => { | ||
const result = babel.transformFileSync(filename, { | ||
presets: [ | ||
['@babel/preset-env', {targets: {node: 'current'}}], | ||
'@babel/preset-typescript'] | ||
}); | ||
return result.code; | ||
}, { | ||
exts: ['.ts'] | ||
}); | ||
}); | ||
|
||
suite.on(Suite.constants.EVENT_FILE_POST_REQUIRE, function(context, file, mocha) { | ||
revertBabelRequire(); | ||
}); | ||
}; | ||
|
||
module.exports = { fixturesUI, fixturePool, registerFixture, registerWorkerFixture }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Mocha = require('mocha'); | ||
const { fixturesUI, fixturePool } = require('./fixturesUI'); | ||
const dot = require('./dot'); | ||
const { Matchers } = require('../../utils/testrunner/Matchers'); | ||
|
||
const browserName = process.env.BROWSER || 'chromium'; | ||
const goldenPath = path.join(__dirname, '..', 'golden-' + browserName); | ||
const outputPath = path.join(__dirname, '..', 'output-' + browserName); | ||
global.expect = new Matchers({ goldenPath, outputPath }).expect; | ||
global.testOptions = require('../harness/testOptions'); | ||
|
||
const mocha = new Mocha({ | ||
ui: fixturesUI, | ||
reporter: dot, | ||
timeout: 10000, | ||
}); | ||
const testDir = path.join(process.cwd(), 'test'); | ||
|
||
const filter = process.argv[2]; | ||
|
||
fs.readdirSync(testDir).filter(function(file) { | ||
return file.includes('.spec.') && (!filter || file.includes(filter)); | ||
}).forEach(function(file) { | ||
mocha.addFile(path.join(testDir, file)); | ||
}); | ||
|
||
const runner = mocha.run((failures) => { | ||
process.exitCode = failures ? 1 : 0; | ||
}); | ||
const constants = Mocha.Runner.constants; | ||
runner.on(constants.EVENT_RUN_END, test => { | ||
fixturePool.teardownScope('worker'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters