Skip to content

Commit

Permalink
tests: adopt jest (leaving mocha) for core & cli (#5386)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and paulirish committed Jun 29, 2018
1 parent 5539ce1 commit aa43403
Show file tree
Hide file tree
Showing 193 changed files with 1,573 additions and 281 deletions.
4 changes: 3 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ test_script:
- yarn --version
- which yarn
- yarn lint
- yarn unit
- yarn unit-core --runInBand
- yarn unit-cli
- yarn unit-viewer
- yarn type-check
# FIXME: Exclude Appveyor from running `perf` smoketest until we fix the flake.
# https://github.com/GoogleChrome/lighthouse/issues/5053
Expand Down
22 changes: 22 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @license Copyright 2018 Google Inc. All Rights Reserved.
* 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.
*/
'use strict';

module.exports = {
collectCoverage: true,
coverageReporters: ['none'],
collectCoverageFrom: [
'**/lighthouse-core/**/*.js',
'**/lighthouse-cli/**/*.js',
'!**/test/',
'!**/scripts/',
],
testEnvironment: 'node',
testMatch: [
'**/lighthouse-core/**/*-test.js',
'**/lighthouse-cli/**/*-test.js',
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/
'use strict';

/* eslint-env mocha */
/* eslint-env jest */
const assert = require('assert');

require('../../bin.js');
const getFlags = require('../../cli-flags').getFlags;

describe('CLI bin', function() {
it('all options should have descriptions', () => {
getFlags('chrome://version');
const yargs = require('yargs');

const optionGroups = yargs.getGroups();
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/test/cli/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
'use strict';

/* eslint-env mocha */
/* eslint-env jest */
const assert = require('assert');
const childProcess = require('child_process');
const path = require('path');
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/test/cli/printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
'use strict';

/* eslint-env mocha */
/* eslint-env jest */
const Printer = require('../../printer.js');
const assert = require('assert');
const fs = require('fs');
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-cli/test/cli/run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
'use strict';

/* eslint-env mocha */
/* eslint-env jest */
const assert = require('assert');
const path = require('path');
const fs = require('fs');
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('CLI run', function() {

fs.unlinkSync(filename);
});
}).timeout(20 * 1000);
}, 20 * 1000);
});

describe('flag coercing', () => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/test/global-mocha-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const assert = require('assert');
* Please keep them in sync.
*/

/* eslint-env mocha */
/* eslint-env jest */
let currTest;

// monkey-patch all assert.* methods
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/report/html/renderer/details-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class DetailsRenderer {
displayedHost = parsed.file === '/' ? '' : `(${parsed.hostname})`;
title = url;
} catch (/** @type {!Error} */ e) {
if (!(e instanceof TypeError)) {
if (!e.name.startsWith('TypeError')) {
throw e;
}
displayedPath = url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/accesskeys.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: accesskeys audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/aria-allowed-attr.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: aria-allowed-attr audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/aria-required-attr.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: aria-required-attr audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/aria-required-children.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: aria-required-children audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/aria-required-parent.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: aria-required-parent audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/aria-roles.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: aria-roles audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/aria-valid-attr.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: aria-valid-attr audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/aria-valid-attr-value.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: aria-valid-attr-value audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/audio-caption.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: audio-caption audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const AxeAudit = require('../../../audits/accessibility/axe-audit');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: axe-audit', () => {
describe('audit()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/button-name.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: button-name audit', () => {
it('generates an audit output', () => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/accessibility/bypass-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/bypass.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: bypass audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/color-contrast.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: color-contrast audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/definition-list.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: definition-list audit', () => {
it('generates an audit output', () => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/accessibility/dlitem-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/dlitem.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: dlitem audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/document-title.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: document-title audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/duplicate-id.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: duplicate-id audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/frame-title.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: frame-title audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/html-has-lang.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: html-has-lang audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/html-lang-valid.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: html-lang-valid audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/image-alt.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: image-alt audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/input-image-alt.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: input-image-alt audit', () => {
it('generates an audit output', () => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/accessibility/label-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/label.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: label audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/layout-table.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: layout-table audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/link-name.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: link-name audit', () => {
it('generates an audit output', () => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/accessibility/list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/list.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: list audit', () => {
it('generates an audit output', () => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/accessibility/listitem-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/listitem.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: listitem audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/meta-refresh.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: meta-refresh audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/meta-viewport.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: meta-viewport audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/object-alt.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: object-alt audit', () => {
it('generates an audit output', () => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/accessibility/tabindex-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/tabindex.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: tabindex audit', () => {
it('generates an audit output', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/accessibility/td-headers-attr.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('Accessibility: td-headers-attr audit', () => {
it('generates an audit output', () => {
Expand Down
Loading

0 comments on commit aa43403

Please sign in to comment.