This repository was archived by the owner on Mar 5, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 78
Implement the basic installation helper #433
Merged
Merged
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 312624f Remove local link to node
dmtrKovalenko e3130a0 Improve helpers
dmtrKovalenko f7845fa Make separate tsconfig.json for building binary scritps
dmtrKovalenko 75dfe66 Rename build step to `bin`
dmtrKovalenko d295cb8 Fix transpiling script
dmtrKovalenko 7a4a9f2 Add test with vitual file system
dmtrKovalenko 36df7ab Implement template payload logic
dmtrKovalenko acc0ef4 Add more tests
dmtrKovalenko 1f92eaf Try to fix CI
dmtrKovalenko 5b61015 Show relative path for webpack config
dmtrKovalenko ddcac9b Create fake bin file before npm i
dmtrKovalenko 189ca1b Add more comprehensive test for webpack code gen
dmtrKovalenko b9cdad5 Try to fix CI v2
dmtrKovalenko 95bc0b3 Add babel template
dmtrKovalenko 2623abc Create rollup example
dmtrKovalenko 9df7b67 Add rollup test
dmtrKovalenko 5665e9e Add additional print helper available
dmtrKovalenko 5126200 Avoid bin links on ci
dmtrKovalenko 6fd6977 Add default webpack options template
dmtrKovalenko 08a382b Merge branch main into feature/smart-installation
dmtrKovalenko 5d6bfc9 Remove not related change from launch.json
dmtrKovalenko b08b9f6 Revert rollup example and template
dmtrKovalenko a99eb02 Read package.json right into string
dmtrKovalenko bb8ee10 Improve error message if cypress is not found
dmtrKovalenko fd1dfd4 Add greeting line explaining the tool running
dmtrKovalenko 56f3610 Make bin/init.js executable
dmtrKovalenko 7b2d681 Apply grammar suggestions from code review
dmtrKovalenko 37a284a Fix more grammar
dmtrKovalenko e8ddbef Merge branch main into feature/smart-installation
dmtrKovalenko 06e639f Fix broken suggestion
dmtrKovalenko 169bf55 Fix test
dmtrKovalenko eba7744 Merge branch 'main' into feature/smart-installation
dmtrKovalenko 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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -8,4 +8,5 @@ package-lock.json | |
| .nyc_output | ||
| coverage | ||
| *.generated.css | ||
| .next | ||
| .next | ||
| bin | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // __mocks__/fs.js | ||
| process.chdir('/') | ||
| module.exports = require('memfs').fs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -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. | ||
| Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will come from PR 444 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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 = | ||
| | { | ||
| Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
bahmutov marked this conversation as resolved. Show resolved Hide resolved | ||
| } | ||
| | { | ||
| 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) | ||
dmtrKovalenko marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| 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 | ||
| } | ||
| }, | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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