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

feat: Implement waitFor #2

Open
wants to merge 12 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"installCommand": "install:csb",
"sandboxes": ["new", "github/kentcdodds/react-testing-library-examples"],
"node": "18"
}
25 changes: 15 additions & 10 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ on:
- 'beta'
- 'alpha'
- '!all-contributors/**'
pull_request: {}
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

jobs:
main:
permissions:
actions: write # to cancel/stop running workflows (styfle/cancel-workflow-action)
contents: read # to fetch code (actions/checkout)
# ignore all-contributors PRs
if: ${{ !contains(github.head_ref, 'all-contributors') }}
strategy:
# Otherwise we would not know if the problem is tied to the Node.js version
fail-fast: false
matrix:
node: [14, 16, 18]
node: [14, 16, 18, 20]
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.0

- name: ⬇️ Checkout repo
uses: actions/checkout@v3
with:
Expand All @@ -43,6 +43,10 @@ jobs:
with:
node-version: ${{ matrix.node }}

# Ideally done by actions/setup-node: https://github.com/actions/setup-node/issues/213
- name: Setup package manager
run: npm install -g npm@9.2.0

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
Expand All @@ -63,18 +67,15 @@ jobs:

release:
permissions:
actions: write # to cancel/stop running workflows (styfle/cancel-workflow-action)
contents: write # to create release tags (cycjimmy/semantic-release-action)
issues: write # to post release that resolves an issue

needs: main
runs-on: ubuntu-latest
if:
${{ github.repository == 'testing-library/web-testing-library' &&
github.event_name == 'push' }}
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.0

- name: ⬇️ Checkout repo
uses: actions/checkout@v3

Expand All @@ -83,6 +84,10 @@ jobs:
with:
node-version: 14

# Ideally done by actions/setup-node: https://github.com/actions/setup-node/issues/213
- name: Setup package manager
run: npm install -g npm@9.2.0

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
Expand Down
22 changes: 14 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ const {

module.exports = {
collectCoverageFrom,
coveragePathIgnorePatterns: [
...coveragePathIgnorePatterns,
'/__tests__/',
'/__node_tests__/',
],
coverageThreshold,
coveragePathIgnorePatterns: [...coveragePathIgnorePatterns, '/__tests__/'],
coverageThreshold: {
...coverageThreshold,
// full coverage across the build matrix (Node.js versions) but not in a single job
// minimum coverage of jobs using different Node.js version
'./src/waitFor.ts': {
branches: 96.77,
functions: 100,
lines: 97.95,
statements: 98,
},
},
watchPlugins: [
...watchPlugins,
require.resolve('jest-watch-select-projects'),
],
projects: [
require.resolve('./tests/jest.config.dom.js'),
require.resolve('./tests/jest.config.node.js'),
// No idea why I need to specify a project instead of having a single config
require.resolve('./tests/jest.config.js'),
],
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@
"jest-watch-select-projects": "^2.0.0",
"jsdom": "^16.4.0",
"kcd-scripts": "^11.0.0",
"pretty-format": "^29.3.1",
"typescript": "^4.1.2"
},
"overrides": {
"browserslist": "4.21.8",
"caniuse-lite": "1.0.30001502"
},
"eslintConfig": {
"extends": [
"./node_modules/kcd-scripts/eslint.js",
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/__snapshots__/waitFor.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`waitFor DOM reference implementation using fake legacy timers timeout 1`] = `Not done`;

exports[`waitFor DOM reference implementation using fake modern timers timeout 1`] = `Not done`;

exports[`waitFor DOM reference implementation using real timers timeout 1`] = `Not done`;
67 changes: 67 additions & 0 deletions src/__tests__/__snapshots__/waitForDOM.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`waitFor DOM reference implementation using fake legacy timers timeout 1`] = `
Not done

Document {
"location": Location {
"assign": [Function assign],
"hash": "",
"host": "localhost",
"hostname": "localhost",
"href": "http://localhost/",
"origin": "http://localhost",
"pathname": "/",
"port": "",
"protocol": "http:",
"reload": [Function reload],
"replace": [Function replace],
"search": "",
"toString": [Function toString],
},
}
`;

exports[`waitFor DOM reference implementation using fake modern timers timeout 1`] = `
Not done

Document {
"location": Location {
"assign": [Function assign],
"hash": "",
"host": "localhost",
"hostname": "localhost",
"href": "http://localhost/",
"origin": "http://localhost",
"pathname": "/",
"port": "",
"protocol": "http:",
"reload": [Function reload],
"replace": [Function replace],
"search": "",
"toString": [Function toString],
},
}
`;

exports[`waitFor DOM reference implementation using real timers timeout 1`] = `
Not done

Document {
"location": Location {
"assign": [Function assign],
"hash": "",
"host": "localhost",
"hostname": "localhost",
"href": "http://localhost/",
"origin": "http://localhost",
"pathname": "/",
"port": "",
"protocol": "http:",
"reload": [Function reload],
"replace": [Function replace],
"search": "",
"toString": [Function toString],
},
}
`;
Loading
Loading