-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added the possibility to run tests in ESM mode (#7411)
<!-- Thank you for your contribution. Before making a PR, please read our contributing guidelines at https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution We recommend creating a *draft* PR, so that you can mark it as 'ready for review' when you are done. --> ## Purpose Add the possibility to run tests in ESM mode ## Approach - [X] Research ways to implement running ESM files consistently - [X] Research ways to compile test files on the run - [X] Add loader hooks for ESM - [X] Run tests with dynamic import - [x] Fix tests - [X] Add handling error `ERR_REQUIRE_ESM` - [X] Add workflow for running tests in ESM - [x] Add additional tests ## References Closes #6853 PR in `bin-v8-flags-filter` DevExpress/bin-v8-flags-filter#1 PR in `callsite-record` inikulin/callsite-record#28 Temp `bin-v8-flags-filter` assembling [bin-v8-flags-filter-1.2.0.zip](https://github.com/DevExpress/testcafe/files/10175237/bin-v8-flags-filter-1.2.0.zip) Temp `callsite-record` assembling [callsite-record-4.1.3.zip](https://github.com/DevExpress/testcafe/files/10175241/callsite-record-4.1.3.zip) ## Pre-Merge TODO - [x] Write tests for your proposed changes - [x] Make sure that existing tests do not fail
- Loading branch information
Showing
143 changed files
with
700 additions
and
272 deletions.
There are no files selected for viewing
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,103 @@ | ||
name: Test Functional (ESM) | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
sha: | ||
desciption: 'The test commit SHA or ref' | ||
required: true | ||
default: 'master' | ||
merged_sha: | ||
description: 'The merge commit SHA' | ||
deploy_run_id: | ||
description: 'The ID of a deployment workspace run with artifacts' | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
environment: test-functional | ||
env: | ||
RETRY_FAILED_TESTS: true | ||
steps: | ||
- uses: actions/github-script@v3 | ||
with: | ||
script: | | ||
await github.repos.createCommitStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
sha: context.payload.inputs.sha, | ||
context: context.workflow, | ||
state: 'pending', | ||
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` | ||
}); | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{github.event.inputs.merged_sha || github.event.inputs.sha}} | ||
|
||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
|
||
- uses: actions/github-script@v3 | ||
with: | ||
script: | | ||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); | ||
let artifacts = {}; | ||
for(let i = 0;i<36&&!artifacts.total_count;i++,await delay(5000)) { | ||
try { | ||
({ data: artifacts } = await github.actions.listWorkflowRunArtifacts({ | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
run_id: context.payload.inputs.deploy_run_id | ||
})); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
const { data: artifact } = await github.request(artifacts.artifacts.find(artifact=> artifact.name === 'npm').archive_download_url); | ||
require('fs').writeFileSync(require('path').join(process.env.GITHUB_WORKSPACE, 'package.zip'), Buffer.from(artifact)) | ||
- run: | | ||
unzip package.zip | ||
tar --strip-components=1 -xzf testcafe-*.tgz | ||
- name: Get npm cache directory | ||
id: npm-cache-dir | ||
run: | | ||
echo "::set-output name=dir::$(npm config get cache)" | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.npm-cache-dir.outputs.dir }} | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- run: npm ci | ||
- run: npx gulp prepare-functional-tests --steps-as-tasks | ||
- run: npm run test-functional-local-headless-chrome-run-esm | ||
timeout-minutes: 60 | ||
- uses: actions/github-script@v3 | ||
with: | ||
script: | | ||
await github.repos.createCommitStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
sha: context.payload.inputs.sha, | ||
context: context.workflow, | ||
state: 'success', | ||
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` | ||
}); | ||
- uses: actions/github-script@v3 | ||
if: failure() || cancelled() | ||
with: | ||
script: | | ||
await github.repos.createCommitStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
sha: context.payload.inputs.sha, | ||
context: context.workflow, | ||
state: 'failure', | ||
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` | ||
}); |
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 |
---|---|---|
|
@@ -14,3 +14,4 @@ Gemfile.lock | |
.npmrc | ||
.DS_Store | ||
!gulp | ||
/test/functional/fixtures/**/package.json |
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 @@ | ||
{ "type": "module" } |
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 @@ | ||
const gulp = require('gulp'); | ||
const globby = require('globby'); | ||
const path = require('path'); | ||
const { Readable } = require('stream'); | ||
|
||
|
||
module.exports = async function createPackageFilesForTests () { | ||
const testFolders = await globby([ | ||
'test/functional/fixtures/**/testcafe-fixtures', | ||
'test/functional/fixtures/**/common', | ||
], { | ||
ignore: ['test/functional/fixtures/**/raw', 'test/functional/fixtures/**/json'], | ||
onlyDirectories: true, | ||
}); | ||
|
||
let stream = new Readable(); | ||
|
||
stream.push('{ "type": "module" }'); | ||
stream.push(null); | ||
|
||
testFolders.forEach(testFolder => { | ||
stream = gulp.src(['gulp/esm-package/package.json']) | ||
.pipe(gulp.dest( path.resolve(testFolder) )); | ||
}); | ||
|
||
return stream; | ||
}; |
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,27 @@ | ||
import exportableLib from './index.js'; | ||
|
||
const { | ||
Role, | ||
ClientFunction, | ||
Selector, | ||
RequestLogger, | ||
RequestMock, | ||
RequestHook, | ||
t, | ||
userVariables, | ||
fixture, | ||
test, | ||
} = exportableLib; | ||
|
||
export { | ||
Role, | ||
ClientFunction, | ||
Selector, | ||
RequestLogger, | ||
RequestMock, | ||
RequestHook, | ||
t, | ||
userVariables, | ||
fixture, | ||
test, | ||
}; |
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
Oops, something went wrong.