Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit e8c8671

Browse files
authored
fix: use pages or src/pages folder for Next.js (#519)
1 parent bf07210 commit e8c8671

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

circle.yml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ workflows:
4747
npm install
4848
echo ***rename root node_modules to avoid accidental dependencies***
4949
mv ../../node_modules ../../no_modules
50-
verify-command: echo 'Already verified'
5150
no-workspace: true
5251
working_directory: examples/a11y
5352
command: npm test
@@ -66,7 +65,6 @@ workflows:
6665
npm install
6766
echo ***rename root node_modules to avoid accidental dependencies***
6867
mv ../../node_modules ../../no_modules
69-
verify-command: echo 'Already verified'
7068
no-workspace: false
7169
working_directory: examples/using-babel
7270
command: npm test
@@ -85,7 +83,6 @@ workflows:
8583
npm install
8684
echo ***rename root node_modules to avoid accidental dependencies***
8785
mv ../../node_modules ../../no_modules
88-
verify-command: echo 'Already verified'
8986
no-workspace: true
9087
working_directory: examples/using-babel-typescript
9188
command: npm test
@@ -106,7 +103,6 @@ workflows:
106103
mv ../../node_modules ../../no_modules
107104
echo ***React version***
108105
npm ls react react-dom
109-
verify-command: echo 'Already verified'
110106
no-workspace: true
111107
working_directory: examples/react-scripts-cucumber
112108
command: npm test
@@ -127,7 +123,6 @@ workflows:
127123
mv ../../node_modules ../../no_modules
128124
echo ***React version***
129125
npm ls react react-dom
130-
verify-command: echo 'Already verified'
131126
no-workspace: true
132127
working_directory: examples/react-scripts
133128
command: npm test
@@ -155,7 +150,6 @@ workflows:
155150
mv ../../node_modules ../../no_modules
156151
echo ***React version***
157152
npm ls react react-dom
158-
verify-command: echo 'Already verified'
159153
no-workspace: true
160154
working_directory: examples/rewired
161155
command: npm test
@@ -174,7 +168,6 @@ workflows:
174168
npm install
175169
echo ***rename root node_modules to avoid accidental dependencies***
176170
mv ../../node_modules ../../no_modules
177-
verify-command: echo 'Already verified'
178171
no-workspace: true
179172
working_directory: examples/nextjs
180173
command: npm test
@@ -202,7 +195,6 @@ workflows:
202195
npm install
203196
echo ***rename root node_modules to avoid accidental dependencies***
204197
mv ../../node_modules ../../no_modules
205-
verify-command: echo 'Already verified'
206198
no-workspace: true
207199
working_directory: examples/react-scripts-folder
208200
command: npm test
@@ -229,7 +221,6 @@ workflows:
229221
npm install
230222
echo ***rename root node_modules to avoid accidental dependencies***
231223
mv ../../node_modules ../../no_modules
232-
verify-command: echo 'Already verified'
233224
no-workspace: true
234225
working_directory: examples/tailwind
235226
command: |
@@ -257,7 +248,6 @@ workflows:
257248
npm install
258249
echo ***rename root node_modules to avoid accidental dependencies***
259250
mv ../../node_modules ../../no_modules
260-
verify-command: echo 'Already verified'
261251
no-workspace: true
262252
working_directory: examples/webpack-file
263253
command: npm test
@@ -283,7 +273,6 @@ workflows:
283273
npm install
284274
echo ***rename root node_modules to avoid accidental dependencies***
285275
mv ../../node_modules ../../no_modules
286-
verify-command: echo 'Already verified'
287276
no-workspace: true
288277
working_directory: examples/webpack5-file
289278
command: npm test
@@ -310,7 +299,6 @@ workflows:
310299
npm install
311300
echo ***rename root node_modules to avoid accidental dependencies***
312301
mv ../../node_modules ../../no_modules
313-
verify-command: echo 'Already verified'
314302
no-workspace: true
315303
working_directory: examples/rollup
316304
command: npm test
@@ -329,7 +317,6 @@ workflows:
329317
npm install
330318
echo ***rename root node_modules to avoid accidental dependencies***
331319
mv ../../node_modules ../../no_modules
332-
verify-command: echo 'Already verified'
333320
no-workspace: true
334321
working_directory: examples/webpack-options
335322
command: npm test
@@ -357,7 +344,6 @@ workflows:
357344
npm install
358345
echo ***rename root node_modules to avoid accidental dependencies***
359346
mv ../../node_modules ../../no_modules
360-
verify-command: echo 'Already verified'
361347
no-workspace: true
362348
working_directory: examples/sass-and-ts
363349
command: npm test
@@ -383,7 +369,6 @@ workflows:
383369
npm install
384370
echo ***rename root node_modules to avoid accidental dependencies***
385371
mv ../../node_modules ../../no_modules
386-
verify-command: echo 'Already verified'
387372
no-workspace: true
388373
working_directory: examples/snapshots
389374
command: npm test
@@ -409,7 +394,6 @@ workflows:
409394
npm install
410395
echo ***rename root node_modules to avoid accidental dependencies***
411396
mv ../../node_modules ../../no_modules
412-
verify-command: echo 'Already verified'
413397
no-workspace: true
414398
working_directory: examples/visual-sudoku
415399
command: npm test
@@ -431,7 +415,6 @@ workflows:
431415
npm install
432416
echo ***rename root node_modules to avoid accidental dependencies***
433417
mv ../../node_modules ../../no_modules
434-
verify-command: echo 'Already verified'
435418
no-workspace: true
436419
working_directory: examples/visual-testing-with-applitools
437420
# to correctly run this job, we need Applitools token
@@ -459,7 +442,6 @@ workflows:
459442
npm install
460443
echo ***rename root node_modules to avoid accidental dependencies***
461444
mv ../../node_modules ../../no_modules
462-
verify-command: echo 'Already verified'
463445
no-workspace: true
464446
working_directory: examples/visual-testing-with-percy
465447
# run Percy agent and then run Cypress component tests
@@ -480,7 +462,6 @@ workflows:
480462
npm install
481463
echo ***rename root node_modules to avoid accidental dependencies***
482464
mv ../../node_modules ../../no_modules
483-
verify-command: echo 'Already verified'
484465
no-workspace: true
485466
working_directory: examples/visual-testing-with-happo
486467
command: npm run test:happo

cypress/component/advanced/mocking-axios/1-users.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const Axios = require('axios')
88
describe('Mocking Axios', () => {
99
it('shows real users', () => {
1010
mount(<Users />)
11-
cy.get('li').should('have.length', 3)
11+
// the first Ajax request could be slow
12+
cy.get('li', { timeout: 15000 }).should('have.length', 3)
1213
})
1314

1415
// https://github.com/bahmutov/cypress-react-unit-test/issues/338

plugins/next/file-preprocessor.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22
const path = require('path')
3+
const fs = require('fs')
34
const debug = require('debug')('cypress-react-unit-test')
45
const loadConfig = require('next/dist/next-server/server/config').default
56
const getNextJsBaseWebpackConfig = require('next/dist/build/webpack-config')
@@ -19,14 +20,21 @@ async function getNextWebpackConfig(config) {
1920

2021
const nextConfig = await loadConfig('development', config.projectRoot)
2122

23+
// determine where the Next.js keeps its pages in this project
24+
// https://nextjs.org/docs/advanced-features/src-directory
25+
const rootPages = path.join(config.projectRoot, 'pages')
26+
const srcPages = path.join(config.projectRoot, 'src', 'pages')
27+
const pagesDir = fs.existsSync(rootPages) ? rootPages : srcPages
28+
if (!fs.existsSync(pagesDir)) {
29+
throw new Error(`Cannot pages folder ${pagesDir}`)
30+
}
31+
2232
const configOptions = {
2333
buildId: `cypress-react-unit-test-${Math.random().toString()}`,
2434
config: nextConfig,
2535
dev: false,
2636
isServer: false,
27-
// assuming the Next.js project has the entire pages in "/pages" subfolder
28-
// https://github.com/bahmutov/cypress-react-unit-test/pull/517
29-
pagesDir: path.join(config.projectRoot, 'pages'),
37+
pagesDir,
3038
entrypoints: {},
3139
rewrites: [],
3240
}

0 commit comments

Comments
 (0)