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 1 commit
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
Add default webpack options template
- Loading branch information
commit 6fd69778ab2bc9d77e4e827cd4229b151912e88a
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
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,122 @@ | ||
| import chalk from 'chalk' | ||
| import highlight from 'cli-highlight' | ||
| import { main, guessTemplateForUsedFramework } from './init' | ||
| import inquirer from 'inquirer' | ||
| import { mockFs, clearMockedFs } from './test/mockFs' | ||
| | ||
| jest.mock('fs') | ||
| jest.mock('inquirer') | ||
| jest.spyOn(global.console, 'log') | ||
| | ||
| describe('end-to-end tests for init script', () => { | ||
| beforeEach(clearMockedFs) | ||
| | ||
| it('automatically suggests to the user which config to use', async () => { | ||
| mockFs({ | ||
| 'cypress.json': '{}', | ||
| 'webpack.config.js': 'module.exports = { }', | ||
| }) | ||
| | ||
| // @ts-ignore | ||
| inquirer.prompt = jest.fn(() => | ||
| Promise.resolve({ | ||
| chosenTemplateName: 'create-react-app', | ||
| componentFolder: 'cypress/component', | ||
| }), | ||
| ) | ||
| | ||
| await main() | ||
| | ||
| const [{ choices, message }] = (inquirer.prompt as any).mock.calls[0][0] | ||
| | ||
| expect(choices[0]).toBe('webpack') | ||
| expect(message).toContain( | ||
| `Press ${chalk.inverse(' Enter ')} to continue with ${chalk.green( | ||
| 'webpack', | ||
| )} configuration`, | ||
| ) | ||
| }) | ||
| | ||
| it('determines more presumable configuration to suggest', async () => { | ||
| mockFs({ | ||
| 'cypress.json': '{}', | ||
| // For next.js user will have babel config, but we want to suggest to use the closest config for the application code | ||
| 'babel.config.js': 'module.exports = { }', | ||
| 'package.json': JSON.stringify({ dependencies: { next: '^9.2.0' } }), | ||
| }) | ||
| | ||
| // @ts-ignore | ||
| inquirer.prompt = jest.fn(() => | ||
| Promise.resolve({ | ||
| chosenTemplateName: 'next.js', | ||
| componentFolder: 'src', | ||
| }), | ||
| ) | ||
| | ||
| await main() | ||
| | ||
| const [{ choices, message }] = (inquirer.prompt as any).mock.calls[0][0] | ||
| | ||
| expect(choices[0]).toBe('next.js') | ||
| expect(message).toContain( | ||
| `Press ${chalk.inverse(' Enter ')} to continue with ${chalk.green( | ||
| 'next.js', | ||
| )} configuration`, | ||
| ) | ||
| }) | ||
| | ||
| it('suggest the right instruction based on user template choice', async () => { | ||
| mockFs({ | ||
| 'cypress.json': '{}', | ||
| }) | ||
| | ||
| // @ts-ignore | ||
| inquirer.prompt = jest.fn(() => | ||
| Promise.resolve({ | ||
| chosenTemplateName: 'create-react-app', | ||
| componentFolder: 'src', | ||
| }), | ||
| ) | ||
| | ||
| await main() | ||
| | ||
| expect(global.console.log).toBeCalledWith( | ||
| `Working example of component tests with ${chalk.green( | ||
| 'create-react-app', | ||
| )}: ${chalk.bold.underline( | ||
| 'https://github.com/bahmutov/cypress-react-unit-test/tree/main/examples/react-scripts', | ||
| )}\n`, | ||
| ) | ||
| }) | ||
| | ||
| it('suggests right docs example and cypress.json config based on the `componentFolder` answer', async () => { | ||
| mockFs({ | ||
| 'cypress.json': '{}', | ||
| }) | ||
| | ||
| // @ts-ignore | ||
| inquirer.prompt = jest.fn(() => | ||
| Promise.resolve({ | ||
| chosenTemplateName: 'create-react-app', | ||
| componentFolder: 'cypress/component', | ||
| }), | ||
| ) | ||
| | ||
| await main() | ||
| | ||
| const expectedCode = highlight( | ||
| JSON.stringify( | ||
| { | ||
| experimentalComponentTesting: true, | ||
| componentFolder: 'cypress/component', | ||
| testFiles: '**/*.spec.{js,ts,jsx,tsx}', | ||
| }, | ||
| null, | ||
| 2, | ||
| ), | ||
| { language: 'json' }, | ||
| ) | ||
| | ||
| expect(global.console.log).toBeCalledWith(`\n${expectedCode}\n`) | ||
| }) | ||
| }) |
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,55 @@ | ||
| import chalk from 'chalk' | ||
| import { Template } from '../Template' | ||
| | ||
| export const WebpackOptions: Template = { | ||
| // this should never show ideally | ||
| message: 'Default template using webpack options', | ||
dmtrKovalenko marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| getExampleUrl: () => | ||
| 'https://github.com/bahmutov/cypress-react-unit-test/tree/main/examples/webpack-options', | ||
| test: () => ({ success: false }), | ||
| recommendedComponentFolder: 'src', | ||
| getPluginsCode: () => | ||
| [ | ||
| `const webpackPreprocessor = require('@cypress/webpack-preprocessor')`, | ||
| ``, | ||
| `// Cypress Webpack preprocessor includes Babel env preset,`, | ||
| `// but to transpile JSX code we need to add Babel React preset`, | ||
| `module.exports = (on, config) => {`, | ||
| ` const opts = webpackPreprocessor.defaultOptions`, | ||
| ` const babelLoader = opts.webpackOptions.module.rules[0].use[0]`, | ||
| ``, | ||
| ` // add React preset to be able to transpile JSX`, | ||
| ` babelLoader.options.presets.push(require.resolve('@babel/preset-react'))`, | ||
| ``, | ||
| ` // We can also push Babel istanbul plugin to instrument the code on the fly`, | ||
| ` // and get code coverage reports from component tests (optional)`, | ||
| ` if (!babelLoader.options.plugins) {`, | ||
| ` babelLoader.options.plugins = []`, | ||
| ` }`, | ||
| ` babelLoader.options.plugins.push(require.resolve('babel-plugin-istanbul'))`, | ||
| ``, | ||
| ` // in order to mock named imports, need to include a plugin`, | ||
| ` babelLoader.options.plugins.push([`, | ||
| ` require.resolve('@babel/plugin-transform-modules-commonjs'),`, | ||
| ` {`, | ||
| ` loose: true,`, | ||
| ` },`, | ||
| ` ])`, | ||
| ``, | ||
| ` // add code coverage plugin`, | ||
| ` require('@cypress/code-coverage/task')(on, config)`, | ||
| ``, | ||
| ` on('file:preprocessor', webpackPreprocessor(opts))`, | ||
| ``, | ||
| ` // if adding code coverage, important to return updated config`, | ||
| ` return config`, | ||
| `}`, | ||
| ].join('\n'), | ||
| printHelper: () => { | ||
| console.log( | ||
| `${chalk.inverse('Important:')} this configuration is using ${chalk.blue( | ||
| 'new webpack configuration ', | ||
| )}to bundle components. If you are using some framework (e.g. next) or bundling tool (e.g. rollup/parcel) consider using them to bundle component specs for cypress. \n`, | ||
| ) | ||
| }, | ||
| } | ||
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.
will come from PR 444