Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: convert lighthouse-core/test to ES modules #13295

Merged
merged 26 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
51516a7
core/test/config
connorjclark Oct 30, 2021
f4b3152
core/test/audits
connorjclark Oct 30, 2021
c25a378
core/test/gather and core/test/fraggle-rock/gather
connorjclark Nov 1, 2021
b3d35a9
workaround the new jest unknown types
connorjclark Nov 1, 2021
aa077f9
core/test/computed
connorjclark Nov 1, 2021
67ead9b
core/test/lib
connorjclark Nov 1, 2021
2d2944d
core/test/fraggle-rock
connorjclark Nov 1, 2021
ec26108
core/test
connorjclark Nov 1, 2021
5f75927
delete extra package.json s
connorjclark Nov 1, 2021
0bfb34d
undo some async stuff
connorjclark Nov 1, 2021
0ca9ad6
fix type in setup file
connorjclark Nov 1, 2021
8abe5a1
Merge remote-tracking branch 'origin/master' into esm-core-1
connorjclark Nov 1, 2021
cdd346a
pr
connorjclark Nov 9, 2021
83f6dbc
Merge remote-tracking branch 'origin/master' into esm-core-1
connorjclark Nov 9, 2021
6ea8233
lint
connorjclark Nov 9, 2021
60fcb3f
Merge remote-tracking branch 'origin/master' into esm-core-1
connorjclark Nov 9, 2021
75484e2
Merge remote-tracking branch 'origin/master' into esm-core-1
connorjclark Nov 16, 2021
b28c493
update
connorjclark Nov 16, 2021
2265777
Merge remote-tracking branch 'origin/master' into esm-core-1
connorjclark Nov 17, 2021
a92c993
pr
connorjclark Nov 17, 2021
0a2942e
Merge remote-tracking branch 'origin/master' into esm-core-1
connorjclark Nov 17, 2021
5272656
merge from master
connorjclark Apr 19, 2022
17aed3e
use json import where possible
connorjclark Apr 20, 2022
ba645e1
Merge remote-tracking branch 'origin/master' into esm-core-1
connorjclark Apr 20, 2022
5f55fbf
Merge remote-tracking branch 'origin/master' into esm-core-1
connorjclark Apr 21, 2022
0f639e2
Merge remote-tracking branch 'origin/master' into esm-core-1
connorjclark Apr 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

module.exports = {
setupFilesAfterEnv: ['./lighthouse-core/test/test-utils.js'],
setupFilesAfterEnv: ['./lighthouse-core/test/jest-setup/setup.js'],
testEnvironment: 'node',
testMatch: [
'**/lighthouse-core/**/*-test.js',
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/driver/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ async function gotoURL(driver, url, options) {
await waitForUserToContinue(driver);
}

log.timeEnd(status);
// TODO: navigation-test fails for some reason without this ...
if (!process.env.JEST_WORKER_ID) log.timeEnd(status);
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
return {
finalUrl,
warnings: getNavigationWarnings({timedOut, finalUrl, requestedUrl: url}),
Expand Down
13 changes: 13 additions & 0 deletions lighthouse-core/scripts/esm-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
'use strict';

import module from 'module';
import url from 'url';
import path from 'path';

const require = module.createRequire(import.meta.url);

Expand All @@ -16,3 +18,14 @@ const require = module.createRequire(import.meta.url);
export function resolveModulePath(packageName) {
return require.resolve(packageName);
}

/**
* Commonjs equivalent of `require.resolve`.
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
* @param {ImportMeta} importMeta
*/
export function createCommonjsRefs(importMeta) {
const require = module.createRequire(importMeta.url);
const filename = url.fileURLToPath(importMeta.url);
const dirname = path.dirname(filename);
return {require, __filename: filename, __dirname: dirname};
}
6 changes: 0 additions & 6 deletions lighthouse-core/test/.prettierrc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/aria-allowed-attr.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/aria-allowed-attr.js';
import {strict as assert} from 'assert';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we want to start doing import assert from 'assert/strict';? Seems way better to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this current form in other places to, so let's handle it everywhere after this PR lands. tracking #13883


/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/aria-required-attr.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/aria-required-attr.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/aria-required-children.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/aria-required-children.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/aria-required-parent.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/aria-required-parent.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/aria-roles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/aria-roles.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/aria-roles.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/aria-valid-attr.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/aria-valid-attr.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/aria-valid-attr-value.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/aria-valid-attr-value.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/axe-audit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const AxeAudit = require('../../../audits/accessibility/axe-audit.js');
const assert = require('assert').strict;
import AxeAudit from '../../../audits/accessibility/axe-audit.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/button-name-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/button-name.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/button-name.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/bypass-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/bypass.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/bypass.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/color-contrast.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/color-contrast.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/definition-list.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/definition-list.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/dlitem-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/dlitem.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/dlitem.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/document-title.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/document-title.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/frame-title-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/frame-title.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/frame-title.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/html-has-lang.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/html-has-lang.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/html-lang-valid.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/html-lang-valid.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/image-alt-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/image-alt.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/image-alt.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/input-image-alt.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/input-image-alt.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/label-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/label.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/label.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/link-name-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/link-name.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/link-name.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/list.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/list.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/listitem-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/listitem.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/listitem.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/meta-refresh.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/meta-refresh.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/meta-viewport.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/meta-viewport.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/object-alt-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/object-alt.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/object-alt.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/tabindex-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/tabindex.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/tabindex.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/td-headers-attr.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/td-headers-attr.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/th-has-data-cells.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/th-has-data-cells.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/accessibility/valid-lang-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/valid-lang.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/valid-lang.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

const Audit = require('../../../audits/accessibility/video-caption.js');
const assert = require('assert').strict;
import Audit from '../../../audits/accessibility/video-caption.js';
import {strict as assert} from 'assert';

/* eslint-env jest */

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/apple-touch-icon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
'use strict';

const AppleTouchIcon = require('../../audits/apple-touch-icon.js');
import AppleTouchIcon from '../../audits/apple-touch-icon.js';

/* eslint-env jest */

Expand Down
Loading