Skip to content

Commit

Permalink
testing: enable chai-as-promised for integ tests (ampproject#27077)
Browse files Browse the repository at this point in the history
* testing: enable chai-as-promised for integ

* lint hack

* try different spot for the hack

* concisify / remove todo

* nits + fixes
  • Loading branch information
samouri authored Mar 12, 2020
1 parent 286109a commit 6b439ae
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 54 deletions.
9 changes: 8 additions & 1 deletion build-system/tasks/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ const MINIFIED_TARGETS = [
*/
const BABELIFY_GLOBAL_TRANSFORM = {
global: true, // Transform node_modules
ignore: devDependencies(), // Ignore devDependencies
/**
* Ignore devDependencies, except for 'chai-as-promised' which contains ES6 code.
* ES6 code is fine for most test environments, but not for integration tests
* running on SauceLabs since some older browsers need ES5.
*/
ignore: devDependencies().filter(
dep => dep.indexOf('chai-as-promised') === -1
),
};

/**
Expand Down
4 changes: 2 additions & 2 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
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');
return 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 @@ -492,6 +492,8 @@ afterEach(function() {
cancelTimersForTesting();
});

chai.use(require('chai-as-promised')); // eslint-disable-line

chai.Assertion.addMethod('attribute', function(attr) {
const obj = this._obj;
const tagName = obj.tagName.toLowerCase();
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 6b439ae

Please sign in to comment.