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

Commit

Permalink
fix: use pages or src/pages folder for Next.js (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov authored Oct 27, 2020
1 parent bf07210 commit e8c8671
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
19 changes: 0 additions & 19 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/a11y
command: npm test
Expand All @@ -66,7 +65,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: false
working_directory: examples/using-babel
command: npm test
Expand All @@ -85,7 +83,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/using-babel-typescript
command: npm test
Expand All @@ -106,7 +103,6 @@ workflows:
mv ../../node_modules ../../no_modules
echo ***React version***
npm ls react react-dom
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/react-scripts-cucumber
command: npm test
Expand All @@ -127,7 +123,6 @@ workflows:
mv ../../node_modules ../../no_modules
echo ***React version***
npm ls react react-dom
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/react-scripts
command: npm test
Expand Down Expand Up @@ -155,7 +150,6 @@ workflows:
mv ../../node_modules ../../no_modules
echo ***React version***
npm ls react react-dom
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/rewired
command: npm test
Expand All @@ -174,7 +168,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/nextjs
command: npm test
Expand Down Expand Up @@ -202,7 +195,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/react-scripts-folder
command: npm test
Expand All @@ -229,7 +221,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/tailwind
command: |
Expand Down Expand Up @@ -257,7 +248,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/webpack-file
command: npm test
Expand All @@ -283,7 +273,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/webpack5-file
command: npm test
Expand All @@ -310,7 +299,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/rollup
command: npm test
Expand All @@ -329,7 +317,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/webpack-options
command: npm test
Expand Down Expand Up @@ -357,7 +344,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/sass-and-ts
command: npm test
Expand All @@ -383,7 +369,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/snapshots
command: npm test
Expand All @@ -409,7 +394,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/visual-sudoku
command: npm test
Expand All @@ -431,7 +415,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/visual-testing-with-applitools
# to correctly run this job, we need Applitools token
Expand Down Expand Up @@ -459,7 +442,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/visual-testing-with-percy
# run Percy agent and then run Cypress component tests
Expand All @@ -480,7 +462,6 @@ workflows:
npm install
echo ***rename root node_modules to avoid accidental dependencies***
mv ../../node_modules ../../no_modules
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/visual-testing-with-happo
command: npm run test:happo
Expand Down
3 changes: 2 additions & 1 deletion cypress/component/advanced/mocking-axios/1-users.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const Axios = require('axios')
describe('Mocking Axios', () => {
it('shows real users', () => {
mount(<Users />)
cy.get('li').should('have.length', 3)
// the first Ajax request could be slow
cy.get('li', { timeout: 15000 }).should('have.length', 3)
})

// https://github.com/bahmutov/cypress-react-unit-test/issues/338
Expand Down
14 changes: 11 additions & 3 deletions plugins/next/file-preprocessor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
const path = require('path')
const fs = require('fs')
const debug = require('debug')('cypress-react-unit-test')
const loadConfig = require('next/dist/next-server/server/config').default
const getNextJsBaseWebpackConfig = require('next/dist/build/webpack-config')
Expand All @@ -19,14 +20,21 @@ async function getNextWebpackConfig(config) {

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

// determine where the Next.js keeps its pages in this project
// https://nextjs.org/docs/advanced-features/src-directory
const rootPages = path.join(config.projectRoot, 'pages')
const srcPages = path.join(config.projectRoot, 'src', 'pages')
const pagesDir = fs.existsSync(rootPages) ? rootPages : srcPages
if (!fs.existsSync(pagesDir)) {
throw new Error(`Cannot pages folder ${pagesDir}`)
}

const configOptions = {
buildId: `cypress-react-unit-test-${Math.random().toString()}`,
config: nextConfig,
dev: false,
isServer: false,
// assuming the Next.js project has the entire pages in "/pages" subfolder
// https://github.com/bahmutov/cypress-react-unit-test/pull/517
pagesDir: path.join(config.projectRoot, 'pages'),
pagesDir,
entrypoints: {},
rewrites: [],
}
Expand Down

0 comments on commit e8c8671

Please sign in to comment.