Skip to content

Commit

Permalink
testing: enable chai-as-promised for integ
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Mar 10, 2020
1 parent 06fa0e8 commit f5f1f04
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 54 deletions.
29 changes: 26 additions & 3 deletions build-system/tasks/runtime-test/runtime-test-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function getFiles(testType) {

switch (testType) {
case 'unit':
files = testConfig.commonUnitTestPaths.concat(testConfig.chaiAsPromised);
files = testConfig.commonUnitTestPaths;
if (argv.files) {
return files.concat(argv.files);
}
Expand All @@ -147,7 +147,7 @@ function getFiles(testType) {
return files.concat(testConfig.integrationTestPaths);

case 'a4a':
return testConfig.chaiAsPromised.concat(testConfig.a4aTestPaths);
return testConfig.a4aTestPaths;

default:
throw new Error(`Test type ${testType} was not recognized`);
Expand Down Expand Up @@ -241,8 +241,31 @@ class RuntimeTestConfig {
// don't overwrite existing plugins
const plugins = [instanbulPlugin].concat(this.babelifyConfig.plugins);

/**
* 'chai-as-promised' contains ES6 code. This is fine for most test environments,
* but not for integration tests running on SauceLabs, since some browsers only
* support ES5 code. Therefore we instruct browserify to transpile the library.
*
* Since browserify doesn't have good support for specifying a node_module to transpile,
* this hack works by saying "transpile everything except for thing in node_modules
* called 'chai-as-promised'".
*/
const babelifyChaiAsPromisedHack =
this.testType !== 'integration'
? {}
: {
global: true,
ignore: [/\/node_modules\/(?!chai-as-promised\/)/],
};
this.browserify.transform = [
['babelify', {...this.babelifyConfig, plugins}],
[
'babelify',
{
...this.babelifyConfig,
...babelifyChaiAsPromisedHack,
plugins,
},
],
];
}
}
Expand Down
3 changes: 0 additions & 3 deletions build-system/test-configs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ const a4aTestPaths = initTestsPath.concat([
'ads/google/a4a/test/*.js',
]);

const chaiAsPromised = ['test/chai-as-promised/chai-as-promised.js'];

const unitTestPaths = [
'test/unit/**/*.js',
'ads/**/test/test-*.js',
Expand Down Expand Up @@ -204,7 +202,6 @@ const changelogIgnoreFileTypes = /\.md|\.json|\.yaml|LICENSE|CONTRIBUTORS$/;
/** @const */
module.exports = {
a4aTestPaths,
chaiAsPromised,
changelogIgnoreFileTypes,
commonIntegrationTestPaths,
commonUnitTestPaths,
Expand Down
9 changes: 2 additions & 7 deletions extensions/amp-bind/0.1/test/integration/test-bind-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,13 +983,8 @@ describe
mystate: {mykey: 'myval'},
});

// Integration tests may not use chai-as-promised.
try {
await bind.getStateAsync('mystate.mykey');
expect.fail();
} catch (err) {
expect(err).match(/#mystate/);
}
const state = bind.getStateAsync('mystate.mykey');
expect(state).to.eventually.rejectedWith(/#mystate/);
});

it('should not wait if the still-loading state is irrelevant', async () => {
Expand Down
2 changes: 2 additions & 0 deletions test/_init_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import PreactEnzyme from 'enzyme-adapter-preact-pure';
import sinon from /*OK*/ 'sinon';
import stringify from 'json-stable-stringify';

chai.use(require('chai-as-promised'));

// Used to print warnings for unexpected console errors.
let that;
let consoleErrorSandbox;
Expand Down
5 changes: 0 additions & 5 deletions test/chai-as-promised/.eslintrc

This file was deleted.

36 changes: 0 additions & 36 deletions test/chai-as-promised/chai-as-promised.js

This file was deleted.

0 comments on commit f5f1f04

Please sign in to comment.