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

Cover 1st-party examples with tests #45270

Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
df87d54
Test selected examples
jankaifer Jan 25, 2023
6487a71
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Jan 25, 2023
4adcd49
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Jan 26, 2023
d6b5a55
add the rest of the examples
jankaifer Jan 27, 2023
d539b41
TYPOs
jankaifer Jan 27, 2023
a1be69e
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Jan 27, 2023
07ba14d
add better logs
jankaifer Jan 27, 2023
daadd6b
fix using-router example
jankaifer Jan 27, 2023
9c97eff
fix dep versions in example
jankaifer Jan 27, 2023
0bfa744
fix outdated deps in example
jankaifer Jan 27, 2023
9214bca
fix unhandled uninitialized var in example
jankaifer Jan 27, 2023
9ee2286
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Jan 27, 2023
4470e8d
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Jan 30, 2023
c3a4dd7
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 2, 2023
c1e6c23
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
kodiakhq[bot] Feb 2, 2023
6e02849
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 2, 2023
0a76e55
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 3, 2023
2850d4f
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 6, 2023
c424ed6
split test into multiple files for performance reasons
jankaifer Feb 6, 2023
7c92114
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 6, 2023
db1f050
reduce number of examples run
jankaifer Feb 6, 2023
3c883e8
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 7, 2023
6b33638
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 7, 2023
404c026
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 14, 2023
10b7f10
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
timneutkens Feb 14, 2023
c9a9696
wip make standalowne workflow for examples
jankaifer Feb 15, 2023
af2e484
refactor example tests
jankaifer Feb 15, 2023
e052d7f
don't execute with cron on forks
jankaifer Feb 15, 2023
f220ab8
better comment
jankaifer Feb 15, 2023
98f5a57
wip
jankaifer Feb 15, 2023
40ef8b7
removed strict equal
jankaifer Feb 15, 2023
c2f6966
fixed copy-pasta
jankaifer Feb 15, 2023
f07baa0
wip
jankaifer Feb 15, 2023
7dda882
wip
jankaifer Feb 15, 2023
70dd3c7
remove unused variables
jankaifer Feb 15, 2023
a6330b6
wip
jankaifer Feb 15, 2023
0cadaef
checkout code
jankaifer Feb 15, 2023
2c0e5a6
wip
jankaifer Feb 15, 2023
dbb865c
mov install to actin itself
jankaifer Feb 15, 2023
8a869c0
fix setup node step
jankaifer Feb 15, 2023
92b045f
added build step
jankaifer Feb 15, 2023
8d39fbc
Enable test for all examples
jankaifer Feb 15, 2023
494d995
increase timeout
jankaifer Feb 16, 2023
9a17e92
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 16, 2023
b35c256
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 17, 2023
eed8fb8
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 23, 2023
bad9f53
refactor to use describe.each
jankaifer Feb 27, 2023
e2f938d
remove needles function
jankaifer Feb 27, 2023
006cb1c
Merge branch 'canary' into jankaifer/next-333-cover-examples-of-inter…
jankaifer Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/test_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This file duplicates bunch of things from build_test_deploy

on:
workflow_dispatch:
inputs:
is_dispatched:
description: 'Leave this option enabled'
required: true
default: true
type: boolean
schedule:
- cron: '0 */4 * * *'

name: Test examples

env:
PNPM_VERSION: 7.24.3

jobs:
testExamples:
# Don't execute using cron on forks
if: (github.repository == 'vercel/next.js') || (inputs.is_dispatched == true)
name: Test Examples
runs-on: ubuntu-latest
timeout-minutes: 120
env:
NEXT_TELEMETRY_DISABLED: 1
strategy:
fail-fast: false
matrix:
node: [16, 18]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 25
# https://github.com/actions/virtual-environments/issues/1187
- name: tune linux network
run: sudo ethtool -K eth0 tx off rx off

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
check-latest: true

- run: npm i -g pnpm@${PNPM_VERSION}

- run: pnpm install
- run: pnpm build

- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=start xvfb-run node run-tests.js --type examples >> /proc/1/fd/1"
name: Run test/examples
7 changes: 5 additions & 2 deletions examples/using-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react": "latest",
"react-dom": "latest",
"typescript": "latest",
"@types/react": "latest",
"@types/node": "latest"
}
}
12 changes: 6 additions & 6 deletions examples/with-typescript-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react": "latest",
"react-dom": "latest"
},
"devDependencies": {
"@types/node": "^12.12.21",
"@types/react": "^16.9.16",
"@types/react-dom": "^16.9.4",
"typescript": "4.0"
"@types/node": "latest",
"@types/react": "latest",
"@types/react-dom": "latest",
"typescript": "4.9.4"
}
}
4 changes: 2 additions & 2 deletions examples/with-web-worker/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export default function Index() {
workerRef.current.onmessage = (event: MessageEvent<number>) =>
alert(`WebWorker Response => ${event.data}`)
return () => {
workerRef.current.terminate()
workerRef.current?.terminate()
}
}, [])

const handleWork = useCallback(async () => {
workerRef.current.postMessage(100000)
workerRef.current?.postMessage(100000)
}, [])

return (
Expand Down
5 changes: 5 additions & 0 deletions run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const testFilters = {
e2e: 'e2e/',
production: 'production/',
development: 'development/',
examples: 'examples/',
}

const mockTrace = () => ({
Expand Down Expand Up @@ -121,6 +122,10 @@ async function main() {
filterTestsBy = testFilters.e2e
break
}
case 'examples': {
filterTestsBy = testFilters.examples
break
}
case 'all':
filterTestsBy = 'none'
break
Expand Down
109 changes: 109 additions & 0 deletions test/examples/examples.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { createNextDescribe } from 'e2e-utils'
import path from 'path'
import fs from 'fs-extra'

const testedExamples = [
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using an allowlist, we might want to change this to an ignorelist so that new examples are automatically tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are not running in normal CI it's actually possible now 👍

We probably should run all examples and we will see in the CI exactly which ones are broken.

But I still think that we want to have a workflow like this with only 1st party examples that should be always green.

And if we start running CI on all examples we need to be extra cautious when adding new libraries because we will be installing that library with access to our CI secrets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add this in Follow-up PR

// Internal features
'active-class-name',
'amp',
'amp-first',
'amp-story',
'api-routes',
'api-routes-cors',
'api-routes-middleware',
'api-routes-rate-limit',
'api-routes-rest',
'app-dir-i18n-routing',
'app-dir-mdx',
'basic-css',
'basic-export',
'blog',
'blog-starter',
'catch-all-routes',
'custom-routes-proxying',
'custom-server',
'data-fetch',
'dynamic-routing',
'environment-variables',
'fast-refresh-demo',
'head-elements',
'headers',
'hello-world',
'hello-world-esm',
'i18n-routing',
'image-component',
'image-legacy-component',
'layout-component',
'middleware',
'middleware-matcher',
'modularize-imports',
'nested-components',
'next-css',
'next-forms',
'progressive-render',
'redirects',
'remove-console',
'reproduction-template',
'rewrites',
'script-component',
'ssr-caching',
'styled-jsx-with-csp',
'svg-components',
'using-router',
'with-absolute-imports',
'with-app-layout',
'with-context-api',
'with-env-from-next-config-js',
'with-loading',
'with-shallow-routing',
'with-sitemap',
'with-typescript',
'with-typescript-types',
'with-web-worker',
'with-webassembly',

// Library integrations that we can't break
'with-jest',
'with-jest-babel',
'with-mdx',
'with-mdx-remote',
'with-tailwindcss',
'with-turbopack',
'with-vercel-fetch',
]

const testExample = (example) => {
const exampleFiles = path.join(__dirname, '..', '..', 'examples', example)

const packageJson = fs.readJsonSync(path.join(exampleFiles, 'package.json'))
describe(`example '${example}'`, () => {
// If there is an issue during a build, jest won't tell us which example caused it
// we need to log it ourselfs
beforeAll(() => {
require('console').log(`Running example '${example}'`)
})
createNextDescribe(
`example '${example}'`,
Copy link
Member

Choose a reason for hiding this comment

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

Is the describe duplicated on line 79 and here on line 86?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, See the comment. We need to fire beforeAll before we fire createNextDescribe, because that's where the actual building happens (and we want to log which example failed).

{
files: exampleFiles,
dependencies: {
// We need to make sure that these default dependencies are not installed by default
// for our examples to ensure that they have all their dependencies in package.json
'@types/node': undefined,
'@types/react': undefined,
next: undefined,
react: undefined,
'react-dom': undefined,
typescript: undefined,
...packageJson.dependencies,
...packageJson.devDependencies,
},
},
() => {
it('builds', () => {})
}
)
})
}

testedExamples.forEach(testExample)
jankaifer marked this conversation as resolved.
Show resolved Hide resolved