Skip to content

Commit

Permalink
convert report tests to mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed May 17, 2022
1 parent 74336c5 commit 9481251
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 22 deletions.
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = {
testEnvironment: 'node',
testMatch: [
'**/lighthouse-core/**/*-test.js',
'**/report/**/*-test.js',
'**/lighthouse-core/test/fraggle-rock/**/*-test-pptr.js',
'**/treemap/**/*-test.js',
'**/viewer/**/*-test.js',
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/scripts/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const args = [
...mochaPassThruArgs,
...filteredTests,
];
if (argv.parallel) args.push('--parallel')
if (argv.parallel) args.push('--parallel');
console.log(`Running command: ${argv.update ? 'SNAPSHOT_UPDATE=1 ' : ''}node ${args.join(' ')}`);

try {
Expand Down
4 changes: 2 additions & 2 deletions report/test/clients/bundle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import fs from 'fs';

import jsdom from 'jsdom';
import {jest} from '@jest/globals';
import jestMock from 'jest-mock';

import * as lighthouseRenderer from '../../clients/bundle.js';
import {LH_ROOT} from '../../../root.js';
Expand All @@ -18,7 +18,7 @@ const sampleResultsStr =
describe('lighthouseRenderer bundle', () => {
let document;
beforeAll(() => {
global.console.warn = jest.fn();
global.console.warn = jestMock.fn();

const {window} = new jsdom.JSDOM();
document = window.document;
Expand Down
4 changes: 3 additions & 1 deletion report/test/generator/report-generator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const fs = require('fs');
const csvValidator = require('csv-validator');

const ReportGenerator = require('../../generator/report-generator.js');
const sampleResults = require('../../../lighthouse-core/test/results/sample_v2.json');
const {readJson} = require('../../../root.js');

const sampleResults = readJson('lighthouse-core/test/results/sample_v2.json');

describe('ReportGenerator', () => {
describe('#replaceStrings', () => {
Expand Down
4 changes: 3 additions & 1 deletion report/test/renderer/category-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {I18n} from '../../renderer/i18n.js';
import {DOM} from '../../renderer/dom.js';
import {DetailsRenderer} from '../../renderer/details-renderer.js';
import {CategoryRenderer} from '../../renderer/category-renderer.js';
import sampleResultsOrig from '../../../lighthouse-core/test/results/sample_v2.json';
import {readJson} from '../../../root.js';

const sampleResultsOrig = readJson('lighthouse-core/test/results/sample_v2.json');

describe('CategoryRenderer', () => {
let renderer;
Expand Down
4 changes: 2 additions & 2 deletions report/test/renderer/dom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import {strict as assert} from 'assert';

import {jest} from '@jest/globals';
import jestMock from 'jest-mock';
import jsdom from 'jsdom';

import {DOM} from '../../renderer/dom.js';
Expand All @@ -26,7 +26,7 @@ describe('DOM', () => {
// The Node version of URL.createObjectURL isn't compatible with the jsdom blob type,
// so we stub it.
nativeCreateObjectURL = URL.createObjectURL;
URL.createObjectURL = jest.fn(_ => `https://fake-origin/blahblah-blobid`);
URL.createObjectURL = jestMock.fn(_ => `https://fake-origin/blahblah-blobid`);

dom = new DOM(window.document);
dom.setLighthouseChannel('someChannel');
Expand Down
4 changes: 3 additions & 1 deletion report/test/renderer/performance-category-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import URL from '../../../lighthouse-core/lib/url-shim.js';
import {DOM} from '../../renderer/dom.js';
import {DetailsRenderer} from '../../renderer/details-renderer.js';
import {PerformanceCategoryRenderer} from '../../renderer/performance-category-renderer.js';
import sampleResultsOrig from '../../../lighthouse-core/test/results/sample_v2.json';
import {readJson} from '../../../root.js';

const sampleResultsOrig = readJson('lighthouse-core/test/results/sample_v2.json');

describe('PerfCategoryRenderer', () => {
let category;
Expand Down
4 changes: 3 additions & 1 deletion report/test/renderer/pwa-category-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {I18n} from '../../renderer/i18n.js';
import {DOM} from '../../renderer/dom.js';
import {DetailsRenderer} from '../../renderer/details-renderer.js';
import {PwaCategoryRenderer} from '../../renderer/pwa-category-renderer.js';
import sampleResultsOrig from '../../../lighthouse-core/test/results/sample_v2.json';
import {readJson} from '../../../root.js';

const sampleResultsOrig = readJson('lighthouse-core/test/results/sample_v2.json');

describe('PwaCategoryRenderer', () => {
let category;
Expand Down
8 changes: 4 additions & 4 deletions report/test/renderer/report-renderer-axe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

import puppeteer from 'puppeteer';

import sampleResults from '../../../lighthouse-core/test/results/sample_v2.json';
import reportGenerator from '../../generator/report-generator.js';
import axeLib from '../../../lighthouse-core/lib/axe.js';
import {readJson} from '../../../root.js';

const sampleResults = readJson('lighthouse-core/test/results/sample_v2.json');

describe('ReportRendererAxe', () => {
describe('with aXe', () => {
Expand Down Expand Up @@ -76,10 +78,8 @@ describe('ReportRendererAxe', () => {
};
});
expect(axeSummary).toMatchSnapshot();
},
}).timeout(20_000);
// This test takes 10s on fast hardware, but can take longer in CI.
// https://github.com/dequelabs/axe-core/tree/b573b1c1/doc/examples/jest_react#timeout-issues
/* timeout= */ 20_000
);
});
});
8 changes: 5 additions & 3 deletions report/test/renderer/report-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
import {strict as assert} from 'assert';

import jsdom from 'jsdom';
import {jest} from '@jest/globals';
import jestMock from 'jest-mock';

import {Util} from '../../renderer/util.js';
import URL from '../../../lighthouse-core/lib/url-shim.js';
import {DOM} from '../../renderer/dom.js';
import {DetailsRenderer} from '../../renderer/details-renderer.js';
import {CategoryRenderer} from '../../renderer/category-renderer.js';
import {ReportRenderer} from '../../renderer/report-renderer.js';
import sampleResultsOrig from '../../../lighthouse-core/test/results/sample_v2.json';
import {readJson} from '../../../root.js';

const sampleResultsOrig = readJson('lighthouse-core/test/results/sample_v2.json');

const TIMESTAMP_REGEX = /\d+, \d{4}.*\d+:\d+/;

Expand All @@ -24,7 +26,7 @@ describe('ReportRenderer', () => {
let sampleResults;

beforeAll(() => {
global.console.warn = jest.fn();
global.console.warn = jestMock.fn();

// Stub out matchMedia for Node.
global.matchMedia = function() {
Expand Down
10 changes: 6 additions & 4 deletions report/test/renderer/report-ui-features-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import {strict as assert} from 'assert';

import jsdom from 'jsdom';
import {jest} from '@jest/globals';
import jestMock from 'jest-mock';

import reportAssets from '../../generator/report-assets.js';
import {Util} from '../../renderer/util.js';
Expand All @@ -16,7 +16,9 @@ import {DetailsRenderer} from '../../renderer/details-renderer.js';
import {ReportUIFeatures} from '../../renderer/report-ui-features.js';
import {CategoryRenderer} from '../../renderer/category-renderer.js';
import {ReportRenderer} from '../../renderer/report-renderer.js';
import sampleResultsOrig from '../../../lighthouse-core/test/results/sample_v2.json';
import {readJson} from '../../../root.js';

const sampleResultsOrig = readJson('lighthouse-core/test/results/sample_v2.json');

describe('ReportUIFeatures', () => {
let sampleResults;
Expand All @@ -39,7 +41,7 @@ describe('ReportUIFeatures', () => {
}

beforeAll(() => {
global.console.warn = jest.fn();
global.console.warn = jestMock.fn();

// Stub out matchMedia for Node.
global.matchMedia = function() {
Expand Down Expand Up @@ -281,7 +283,7 @@ describe('ReportUIFeatures', () => {
const getSaveEl = () => dom.find('a[data-action="save-html"]', container);
expect(getSaveEl().classList.contains('lh-hidden')).toBeTruthy();

const getHtmlMock = jest.fn();
const getHtmlMock = jestMock.fn();
container = render(sampleResults, {
getStandaloneReportHTML: getHtmlMock,
});
Expand Down
4 changes: 3 additions & 1 deletion report/test/renderer/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {strict as assert} from 'assert';

import {Util} from '../../renderer/util.js';
import {I18n} from '../../renderer/i18n.js';
import sampleResult from '../../../lighthouse-core/test/results/sample_v2.json';
import {readJson} from '../../../root.js';

const sampleResult = readJson('lighthouse-core/test/results/sample_v2.json');

describe('util helpers', () => {
beforeEach(() => {
Expand Down

0 comments on commit 9481251

Please sign in to comment.