-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(crx-tests): run tests inside chrome extension
We send the test body to run in a chrome extension service worker. For now, only tests depending on basic server info and page are supported (all others are skipped). Also, if the test closure includes external objects other that `test` and `except`, it will fail.
- Loading branch information
1 parent
25b3bbb
commit 872a755
Showing
13 changed files
with
1,047 additions
and
21 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* 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. | ||
*/ | ||
|
||
const noop = () => {}; | ||
|
||
export const wrapFunctionWithLocation = noop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* 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. | ||
*/ | ||
|
||
// @ts-nocheck | ||
|
||
import { promisify as _promisify, inspect, types, isString, inherits, format } from '_util'; | ||
export { inspect, types, isString, inherits, format } from '_util'; | ||
|
||
export const promisify = function(first, ...rest) { | ||
if (first !== 'function') return Promise.resolve(); | ||
return _promisify(first, ...rest); | ||
}; | ||
|
||
export default { promisify, inspect, types, isString, inherits, format }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* 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. | ||
*/ | ||
|
||
import type { Worker } from 'playwright-core'; | ||
import { getRequiredFixtureNames } from './fixtureRunner'; | ||
import type { TestInfoImpl } from './testInfo'; | ||
|
||
export default class CrxTestRunner { | ||
private _testInfo: TestInfoImpl; | ||
|
||
constructor(testInfo: TestInfoImpl) { | ||
this._testInfo = testInfo; | ||
} | ||
|
||
isCrxTest() { | ||
return process.env.PWPAGE_IMPL === 'crx'; | ||
} | ||
|
||
isToSkip() { | ||
const names = getRequiredFixtureNames(this._testInfo.fn); | ||
return !names.every(name => ['page', 'server', 'browserName'].includes(name)); | ||
} | ||
|
||
async run(testFunctionParams: object | null) { | ||
const { page, server: serverObj, browserName } = testFunctionParams as any; | ||
const worker = page?.extensionServiceWorker as Worker; | ||
|
||
if (!worker) throw new Error(`could not find extensionServiceWorker0`); | ||
|
||
let server; | ||
if (serverObj) { | ||
const { PORT, PREFIX, CROSS_PROCESS_PREFIX, EMPTY_PAGE } = serverObj; | ||
server = { PORT, PREFIX, CROSS_PROCESS_PREFIX, EMPTY_PAGE }; | ||
} | ||
const fn = this._testInfo.fn; | ||
const fnBody = fn.toString() | ||
.replaceAll(/\w+\.expect/g, 'expect') | ||
.replaceAll(/\_\w+Test\.test/g, 'test'); | ||
await worker.evaluate(new Function(`return async (fixtures) => { | ||
const { test, expect } = self; | ||
await runTest(fixtures, ${fnBody}); | ||
}`)(), { server, browserName }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters