Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
51e7ef5
Implement the basic installation helper
dmtrKovalenko Sep 17, 2020
312624f
Remove local link to node
dmtrKovalenko Sep 17, 2020
e3130a0
Improve helpers
dmtrKovalenko Sep 18, 2020
f7845fa
Make separate tsconfig.json for building binary scritps
dmtrKovalenko Sep 18, 2020
75dfe66
Rename build step to `bin`
dmtrKovalenko Sep 18, 2020
d295cb8
Fix transpiling script
dmtrKovalenko Sep 18, 2020
7a4a9f2
Add test with vitual file system
dmtrKovalenko Sep 21, 2020
36df7ab
Implement template payload logic
dmtrKovalenko Sep 21, 2020
acc0ef4
Add more tests
dmtrKovalenko Sep 21, 2020
1f92eaf
Try to fix CI
dmtrKovalenko Sep 21, 2020
5b61015
Show relative path for webpack config
dmtrKovalenko Sep 22, 2020
ddcac9b
Create fake bin file before npm i
dmtrKovalenko Sep 22, 2020
189ca1b
Add more comprehensive test for webpack code gen
dmtrKovalenko Sep 22, 2020
b9cdad5
Try to fix CI v2
dmtrKovalenko Sep 22, 2020
95bc0b3
Add babel template
dmtrKovalenko Sep 22, 2020
2623abc
Create rollup example
dmtrKovalenko Sep 22, 2020
9df7b67
Add rollup test
dmtrKovalenko Sep 22, 2020
5665e9e
Add additional print helper available
dmtrKovalenko Sep 22, 2020
5126200
Avoid bin links on ci
dmtrKovalenko Sep 22, 2020
6fd6977
Add default webpack options template
dmtrKovalenko Sep 23, 2020
08a382b
Merge branch main into feature/smart-installation
dmtrKovalenko Sep 23, 2020
5d6bfc9
Remove not related change from launch.json
dmtrKovalenko Sep 23, 2020
b08b9f6
Revert rollup example and template
dmtrKovalenko Sep 23, 2020
a99eb02
Read package.json right into string
dmtrKovalenko Sep 23, 2020
bb8ee10
Improve error message if cypress is not found
dmtrKovalenko Sep 23, 2020
fd1dfd4
Add greeting line explaining the tool running
dmtrKovalenko Sep 23, 2020
56f3610
Make bin/init.js executable
dmtrKovalenko Sep 23, 2020
7b2d681
Apply grammar suggestions from code review
dmtrKovalenko Sep 28, 2020
37a284a
Fix more grammar
dmtrKovalenko Sep 28, 2020
e8ddbef
Merge branch main into feature/smart-installation
dmtrKovalenko Sep 28, 2020
06e639f
Fix broken suggestion
dmtrKovalenko Sep 28, 2020
169bf55
Fix test
dmtrKovalenko Sep 28, 2020
eba7744
Merge branch 'main' into feature/smart-installation
dmtrKovalenko Sep 29, 2020
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ package-lock.json
.nyc_output
coverage
*.generated.css
.next
.next
bin
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch init script",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"skipFiles": ["<node_internals>/**"],
"cwd": "${workspaceRoot}",
"program": "${workspaceFolder}/init/init.ts",
"outFiles": ["${workspaceFolder}/**/*.js"]
},
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand", "${fileBasenameNoExtension}"],
"sourceMaps": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
}
]
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ Folder Name | Description
[visual-testing-with-happo](examples/visual-testing-with-happo) | [Visual testing](#visual-testing) for components using 3rd party service [Happo](https://happo.io/)
[visual-testing-with-applitools](examples/visual-testing-with-applitools) | [Visual testing](#visual-testing) for components using 3rd party service [Applitools.com](https://applitools.com/)
[using-babel](examples/using-babel) | Bundling specs and loaded source files using project's existing `.babelrc` file
[webpack-file](examples/rollup) | Bundle component and specs using [rollup](http://rollupjs.org/guide/en/).
Copy link
Contributor

Choose a reason for hiding this comment

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

ughh, Dmitry, why can't you separate adding Rollup support from the CLI wizard

Copy link
Contributor

Choose a reason for hiding this comment

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

hehe should go into 444

[webpack-file](examples/webpack-file) | Load existing `webpack.config.js` file
[webpack-options](examples/webpack-options) | Using the default Webpack options from `@cypress/webpack-preprocessor` to transpile JSX specs
<!-- prettier-ignore-end -->
Expand Down
3 changes: 3 additions & 0 deletions __mocks__/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// __mocks__/fs.js
process.chdir('/')
module.exports = require('memfs').fs
35 changes: 19 additions & 16 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ workflows:
- run:
name: Build folder 🏗
command: npm run build
- run:
name: Run unit tests 👷
command: npm run test:unit

- cypress/run:
name: Example A11y
requires:
- Install
executor: cypress/base-12
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/a11y
Expand All @@ -45,9 +48,9 @@ workflows:
- Install
executor: cypress/base-12
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
no-workspace: false
working_directory: examples/using-babel
command: npm test
store_artifacts: true
Expand All @@ -58,7 +61,7 @@ workflows:
- Install
executor: cypress/base-12
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/using-babel-typescript
Expand All @@ -71,7 +74,7 @@ workflows:
- Install
executor: cypress/base-12
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/react-scripts
Expand All @@ -91,7 +94,7 @@ workflows:
- Install
executor: cypress/base-12
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/nextjs
Expand All @@ -113,7 +116,7 @@ workflows:
requires:
- Install
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/react-scripts-folder
Expand All @@ -133,7 +136,7 @@ workflows:
- Install
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
executor: cypress/base-12
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/tailwind
Expand All @@ -155,7 +158,7 @@ workflows:
- Install
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
executor: cypress/base-12
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/webpack-file
Expand All @@ -175,7 +178,7 @@ workflows:
- Install
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
executor: cypress/base-12
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/webpack-options
Expand All @@ -197,7 +200,7 @@ workflows:
# because we will use native Sass dependency
executor: cypress/base-12
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/sass-and-ts
Expand All @@ -217,7 +220,7 @@ workflows:
- Install
executor: cypress/base-12
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/snapshots
Expand All @@ -230,7 +233,7 @@ workflows:
requires:
- Install
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/visual-sudoku
Expand All @@ -246,7 +249,7 @@ workflows:
requires:
- Install
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/visual-testing-with-applitools
Expand All @@ -268,7 +271,7 @@ workflows:
requires:
- Install
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/visual-testing-with-percy
Expand All @@ -283,7 +286,7 @@ workflows:
requires:
- Install
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
install-command: npm install --no-bin-links
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/visual-testing-with-happo
Expand Down
34 changes: 34 additions & 0 deletions docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,37 @@ When loading your `.babelrc` settings, `cypress-react-unit-test` sets `BABEL_ENV
```

See [examples/using-babel](examples/using-babel) folder for full example.

### Using rollup config

If you are using rollup for bundling – we can use it as well for the bundling. Check the example:

```js
// // cypress/plugins/index.js
const rollupPreprocessor = require('@bahmutov/cy-rollup')

module.exports = (on, config) => {
on(
'file:preprocessor',
rollupPreprocessor({
// this is the default value
configFile: 'rollup.config.js',
}),
)

require('@cypress/code-coverage/task')(on, config)
}
```

But make sure that several rollup plugins are required in order to bundle the code for cypress.

```js
// bundle node_modules
nodeResolve(),
// process commonjs modules
commonjs(),
// required for react (prop-types) sources
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
```

See [examples/rollup](examples/rollup) folder for full example.
Copy link
Contributor

Choose a reason for hiding this comment

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

will come from PR 444

11 changes: 11 additions & 0 deletions init/Template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface Template<T = unknown> {
message: string
getExampleUrl: ({ componentFolder }: { componentFolder: string }) => string
recommendedComponentFolder: string
test(rootPath: string): { success: boolean; payload?: T }
getPluginsCode: (
payload: T | null,
options: { cypressProjectRoot: string },
) => string
printHelper?: () => void
}
85 changes: 85 additions & 0 deletions init/findPackageJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import path from 'path'
import fs from 'fs'
import findUp from 'find-up'

type PackageJsonLike = {
name?: string
scripts?: Record<string, string>
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
[key: string]: unknown
}

type FindPackageJsonResult =
| {
Copy link
Contributor

Choose a reason for hiding this comment

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

haha, we don't need no monads

packageData: PackageJsonLike
filename: string
done: false
}
| {
packageData: undefined
filename: undefined
done: true
}

/**
* Return the parsed package.json that we find in a parent folder.
*
* @returns {Object} Value, filename and indication if the iteration is done.
*/
export function createFindPackageJsonIterator(rootPath = process.cwd()) {
function scanForPackageJson(cwd: string): FindPackageJsonResult {
const packageJsonPath = findUp.sync('package.json', { cwd })
if (!packageJsonPath) {
return {
packageData: undefined,
filename: undefined,
done: true,
}
}

const packageJsonBuffer = fs.readFileSync(packageJsonPath)
const packageData = JSON.parse(packageJsonBuffer.toString('utf-8'))

return {
packageData,
filename: packageJsonPath,
done: false,
}
}

return {
map: <TPayload>(
cb: (
data: PackageJsonLike,
packageJsonPath: string,
) => { continue: boolean; payload?: TPayload },
) => {
let stepPathToScan = rootPath

while (true) {
const result = scanForPackageJson(stepPathToScan)

if (result.done) {
// didn't find the package.json
return { success: false }
}

if (result.packageData) {
const cbResult = cb(result.packageData, result.filename)
if (!cbResult.continue) {
return { success: true, payload: cbResult.payload }
}
}

const nextStepPathToScan = path.resolve(stepPathToScan, '..')
if (nextStepPathToScan === stepPathToScan) {
// we are at the root. Give up
return { success: false }
}

stepPathToScan = nextStepPathToScan
}
},
}
}
Loading