Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create-cypress-tests wizard #8857

Merged
merged 82 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
6d3454d
Remove unused stuff
dmtrKovalenko Oct 1, 2020
37fe4e4
Fix eslint errors
dmtrKovalenko Oct 1, 2020
1159576
Use local cypress running script
dmtrKovalenko Oct 1, 2020
01a70be
Fix dependency resolution
dmtrKovalenko Oct 1, 2020
5405445
Revert "Fix dependency resolution"
dmtrKovalenko Oct 1, 2020
67f8bde
Add @cypress/react CI
dmtrKovalenko Oct 1, 2020
d698ce1
Properly resolve @types pacakges
dmtrKovalenko Oct 2, 2020
f52b5b5
Run tests with mocha
dmtrKovalenko Oct 2, 2020
2a2e5ca
Fix cypress tests
dmtrKovalenko Oct 2, 2020
7c15e6e
Fix or skip some specs
dmtrKovalenko Oct 2, 2020
1892590
Add retries to the card-spec.js
dmtrKovalenko Oct 2, 2020
0a4a576
Remove jest mocks
dmtrKovalenko Oct 5, 2020
d65280e
Run e2e examples on CI
dmtrKovalenko Oct 6, 2020
72b1dd3
Fix yarn cache key
dmtrKovalenko Oct 6, 2020
efcc7c4
Fix e2e examples jobs
dmtrKovalenko Oct 6, 2020
4febfcc
Rename cypress-react-unit-test with @cypress/react
dmtrKovalenko Oct 6, 2020
7f25f05
Fix circleci.yml
dmtrKovalenko Oct 6, 2020
b9b4ecb
Revert "Fix e2e examples jobs"
dmtrKovalenko Oct 6, 2020
18da2e8
Revert " Rename cypress-react-unit-test with @cypress/react"
dmtrKovalenko Oct 6, 2020
badbe3e
Replce cypress-react-unit-test with @cypress/react
dmtrKovalenko Oct 6, 2020
4cae939
Persist build artifacts
dmtrKovalenko Oct 6, 2020
3467961
Fix working directory paths circle.yml
dmtrKovalenko Oct 6, 2020
b5f31da
Fix more CI
dmtrKovalenko Oct 6, 2020
66c07b2
adding yarn.lock files
JessicaSachs Oct 8, 2020
c7583d1
Make package.json for folder
dmtrKovalenko Oct 8, 2020
0138206
Remove .npmrc
dmtrKovalenko Oct 8, 2020
e9e875c
Update circle.yml
dmtrKovalenko Oct 8, 2020
e0e7789
Remove unused files
dmtrKovalenko Oct 8, 2020
6625b73
Copy plugins files to the "dist" folder
dmtrKovalenko Oct 8, 2020
49dfab8
Fix links to the github repos
dmtrKovalenko Oct 13, 2020
e39ffd6
Merge branch 'master' into 'fix/make-imported-cypress/react-work'
dmtrKovalenko Oct 13, 2020
6cd445c
Move init wizard from npm/react/init to npm/wizard
dmtrKovalenko Oct 13, 2020
0711c6c
Move init wizard from npm/react/init to npm/wizard
dmtrKovalenko Oct 14, 2020
04d5bf3
Implement initial vue template
dmtrKovalenko Oct 15, 2020
f98bbd9
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Oct 16, 2020
8d0aed7
Run wizard tests on CI
dmtrKovalenko Oct 16, 2020
b34035e
Refactor continue: bool to success: bool for better code readability
dmtrKovalenko Oct 16, 2020
cbc5eb4
Fix circleci.yml
dmtrKovalenko Oct 16, 2020
62c3d89
Use only absolute paths for tests
dmtrKovalenko Oct 19, 2020
0a15585
Merge conflicts
dmtrKovalenko Oct 19, 2020
b528fc3
Stub process.exit calls
dmtrKovalenko Oct 19, 2020
b52eac2
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Oct 22, 2020
8b91dbe
Remove useless comments
dmtrKovalenko Oct 22, 2020
f4b5d7f
Add installation cypress to the wizard logic
dmtrKovalenko Oct 27, 2020
abb34ba
More improvements
dmtrKovalenko Oct 27, 2020
f15d78b
Include packages/examples/cypress into git
dmtrKovalenko Oct 28, 2020
31ea113
Commit new files
dmtrKovalenko Oct 28, 2020
c3e4774
Use packages/example as SST for generated files
dmtrKovalenko Oct 28, 2020
f266f40
Last improvements for wizard
dmtrKovalenko Oct 28, 2020
a509b78
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Oct 28, 2020
5fc8159
Update packages/server/lib/scaffold.js
dmtrKovalenko Oct 28, 2020
e0b2125
Rename wizard to create-cypress-tests
dmtrKovalenko Oct 28, 2020
9c21804
Fix circleci config
dmtrKovalenko Oct 28, 2020
585732c
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 2, 2020
7dc1d7b
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 2, 2020
b53fb1a
Fix snapshot tests
dmtrKovalenko Nov 3, 2020
2d5e5c4
Run all create-cypress-tests on ci
dmtrKovalenko Nov 6, 2020
cf5ed8f
Do not install plugins and scaffold files from kitchensink
dmtrKovalenko Nov 6, 2020
41e8b06
Ignore integration/examples folder for packages/example
dmtrKovalenko Nov 6, 2020
911b921
Run create-cypress-tests-tests on CI
dmtrKovalenko Nov 6, 2020
47470bf
Add copy example cross-platform script
dmtrKovalenko Nov 9, 2020
d0f74b1
Use copy example script in tests
dmtrKovalenko Nov 9, 2020
1cb6d06
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 9, 2020
8f34fae
feat: create-cypress-tests auto-inject config (#9116)
dmtrKovalenko Nov 19, 2020
76fbb9a
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 19, 2020
805d9f1
Prepeare package for the release
dmtrKovalenko Nov 19, 2020
eb69592
Fix inquirer name
dmtrKovalenko Nov 19, 2020
389e92b
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 19, 2020
66aeb47
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 23, 2020
1653460
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 23, 2020
62124ca
v0.0.125
dmtrKovalenko Nov 23, 2020
665b87f
v0.0.127
dmtrKovalenko Nov 23, 2020
22bcb3c
v0.0.128
dmtrKovalenko Nov 23, 2020
92545dd
v0.0.130
dmtrKovalenko Nov 23, 2020
0df98bc
v0.0.131
dmtrKovalenko Nov 23, 2020
d86c100
Add more UX features
dmtrKovalenko Nov 24, 2020
398a7ff
Add vue-cli template
dmtrKovalenko Nov 24, 2020
2f4cb8c
Make src as default folder for vue-cli template
dmtrKovalenko Nov 24, 2020
c82cbd5
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 24, 2020
8069c6e
Revert dev-time changes
dmtrKovalenko Nov 24, 2020
499b05c
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 24, 2020
c0ecb3e
Merge branch 'develop' into feature/cross-platform-wizard
dmtrKovalenko Nov 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ npm/webpack-preprocessor/examples/use-babelrc/cypress/integration/spec.js
**/.cy
**/.git

/npm/react/bin/*
/npm/react/bin/*
/npm/react/**/coverage
**/.next/**
/npm/create-cypress-tests/initial-template
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ npm/**/cypress/screenshots
# from example
packages/example/app
packages/example/build
packages/example/cypress
packages/example/cypress/integration

# from server
packages/server/.cy
Expand All @@ -39,6 +39,10 @@ packages/server/test/support/fixtures/server/libs
/npm/react/bin/*
/npm/react/cypress/videos

# from npm/create-cypress-tests
/npm/create-cypress-tests/initial-template
/npm/create-cypress-tests/src/test-output

# Building app binary
scripts/support
package-lock.json
Expand Down
20 changes: 16 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,6 @@ jobs:
- run:
name: Build
command: yarn workspace @cypress/react build
- run:
name: Run unit test
command: yarn workspace @cypress/react test:unit
- run:
name: Run tests
command: yarn workspace @cypress/react test
Expand Down Expand Up @@ -984,7 +981,18 @@ jobs:
name: Run e2e example tests
command: yarn test
working_directory: npm/react/<<parameters.path>>



npm-create-cypress-tests:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: yarn workspace create-cypress-tests build
- run:
name: Run unit test
command: yarn workspace create-cypress-tests test

npm-eslint-plugin-dev:
<<: *defaults
steps:
Expand Down Expand Up @@ -1813,6 +1821,10 @@ linux-workflow: &linux-workflow
path: examples/webpack-options
requires:
- npm-react

- npm-create-cypress-tests:
requires:
- build

- npm-eslint-plugin-dev:
requires:
Expand Down
37 changes: 37 additions & 0 deletions npm/create-cypress-tests/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"plugins": [
"cypress",
"@cypress/dev"
],
"extends": [
"plugin:@cypress/dev/general"
],
"parser": "@typescript-eslint/parser",
"env": {
"cypress/globals": true
},
"rules": {
"no-console": "off",
"mocha/no-global-tests": "off",
"@typescript-eslint/no-unused-vars": "off"
},
"overrides": [
{
"files": [
"lib/*"
],
"rules": {
"no-console": 1
}
},
{
"files": [
"**/*.json"
],
"rules": {
"quotes": "off",
"comma-dangle": "off"
}
}
]
}
7 changes: 7 additions & 0 deletions npm/create-cypress-tests/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"watch-ignore": [
"node_modules"
],
"require": "ts-node/register",
"exit": true
}
1 change: 1 addition & 0 deletions npm/create-cypress-tests/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
35 changes: 35 additions & 0 deletions npm/create-cypress-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "create-cypress-tests",
"version": "0.0.0",
"description": "Smart installation wizard",
"private": false,
"main": "index.js",
"scripts": {
"build": "yarn prepare-example && tsc -p ./tsconfig.json && chmod +x dist/src/index.js && node scripts/example copy-to ./dist/initial-template",
"prepare-example": "node scripts/example copy-to ./initial-template",
"test": "cross-env TS_NODE_PROJECT=./tsconfig.test.json mocha --config .mocharc.json './src/**/*.test.ts'"
},
"dependencies": {
"chalk": "4.1.0",
"cli-highlight": "2.1.4",
"commander": "6.1.0",
"find-up": "5.0.0",
"inquirer": "7.3.3",
"ora": "^5.1.0"
},
"devDependencies": {
"@types/inquirer": "7.3.1",
"@types/mock-fs": "4.10.0",
"@types/node": "9.6.49",
"@types/ora": "^3.2.0",
"mocha": "7.1.1",
"mock-fs": "4.13.0",
"typescript": "4.0.3"
},
"bin": {
"create-cypress-tests": "dist/src/index.js"
},
"license": "MIT",
"repository": "https://github.com/cypress-io/cypress.git",
"author": "Cypress.io team"
}
19 changes: 19 additions & 0 deletions npm/create-cypress-tests/scripts/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require('fs-extra')
const chalk = require('chalk')
const path = require('path')
const program = require('commander')

program
.command('copy-to [destination]')
.description('copy cypress/packages/example into destination')
.action(async (destination) => {
const exampleFolder = path.resolve(__dirname, '..', '..', '..', 'packages', 'example')
const destinationPath = path.resolve(process.cwd(), destination)

await fs.remove(destinationPath)
await fs.copy(exampleFolder, destinationPath, { recursive: true })

console.log(`✅ Example was successfully created at ${chalk.cyan(destination)}`)
})

program.parse(process.argv)
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { expect, use } from 'chai'
import sinon, { SinonStub, SinonSpy } from 'sinon'
import chalk from 'chalk'
import mockFs from 'mock-fs'
import highlight from 'cli-highlight'
import { initComponentTesting } from './init-component-testing'
import inquirer from 'inquirer'
import sinonChai from 'sinon-chai'
import childProcess from 'child_process'
import { someOfSpyCallsIncludes } from '../test-utils'

use(sinonChai)

describe('init component tests script', () => {
let promptSpy: SinonStub<any> | null = null
let logSpy: SinonSpy | null = null
let processExitStub: SinonStub<any> | null = null
let execStub: SinonStub | null = null

beforeEach(() => {
logSpy = sinon.spy(global.console, 'log')
// @ts-ignores
execStub = sinon.stub(childProcess, 'exec').callsFake((command, callback) => callback())
processExitStub = sinon.stub(process, 'exit').callsFake(() => {
throw new Error(`${chalk.red('process.exit')} should not be called`)
})
})

afterEach(() => {
mockFs.restore()
logSpy?.restore()
promptSpy?.restore()
processExitStub?.restore()
execStub?.restore()
})

it('automatically suggests to the user which config to use', async () => {
mockFs({
'/cypress.json': '{}',
'/package.json': JSON.stringify({
dependencies: {
react: '^16.10.0',
},
}),
'/webpack.config.js': 'module.exports = { }',
}, { createCwd: true })

promptSpy = sinon.stub(inquirer, 'prompt').returns(Promise.resolve({
chosenTemplateName: 'create-react-app',
componentFolder: 'cypress/component',
}) as any)

await initComponentTesting({ config: {}, cypressConfigPath: '/', useYarn: true })
const [{ choices, message }] = (inquirer.prompt as any).args[0][0]

expect(choices[0]).to.equal('webpack')
expect(message).to.contain(
`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: { react: '^17.x', next: '^9.2.0' } }),
})

promptSpy = sinon.stub(inquirer, 'prompt').returns(Promise.resolve({
chosenTemplateName: 'next.js',
componentFolder: 'src',
}) as any)

await initComponentTesting({ config: {}, cypressConfigPath: '/', useYarn: true })

const [{ choices, message }] = (inquirer.prompt as any).args[0][0]

expect(choices[0]).to.equal('next.js')
expect(message).to.contain(
`Press ${chalk.inverse(' Enter ')} to continue with ${chalk.green(
'next.js',
)} configuration`,
)
})

it('Asks for framework if can not determine the right one', async () => {
mockFs({
'/cypress.json': '{}',
'/webpack.config.js': 'module.exports = { }',
'/package.json': JSON.stringify({ dependencies: { } }),
})

promptSpy = sinon.stub(inquirer, 'prompt')
.onCall(0)
.returns(Promise.resolve({
framework: 'vue',
}) as any)
.onCall(1)
.returns(Promise.resolve({
chosenTemplateName: 'webpack',
componentFolder: 'src',
}) as any)

await initComponentTesting({ config: {}, cypressConfigPath: '/', useYarn: true })

expect(
someOfSpyCallsIncludes(global.console.log, 'We were unable to automatically determine your framework 😿'),
).to.be.true
})

it('Asks for framework if more than 1 option was auto detected', async () => {
mockFs({
'/cypress.json': '{}',
'/webpack.config.js': 'module.exports = { }',
'/package.json': JSON.stringify({ dependencies: { react: '*', vue: '*' } }),
})

promptSpy = sinon.stub(inquirer, 'prompt')
.onCall(0)
.returns(Promise.resolve({
framework: 'vue',
}) as any)
.onCall(1)
.returns(Promise.resolve({
chosenTemplateName: 'webpack',
componentFolder: 'src',
}) as any)

await initComponentTesting({ config: {}, cypressConfigPath: '/', useYarn: true })

expect(
someOfSpyCallsIncludes(global.console.log, `It looks like all these frameworks: ${chalk.yellow('react, vue')} are available from this directory.`),
).to.be.true
})

it('suggest the right instruction based on user template choice', async () => {
mockFs({
'/package.json': JSON.stringify({
dependencies: {
react: '^16.0.0',
},
}),
'/cypress.json': '{}',
})

promptSpy = sinon.stub(inquirer, 'prompt').returns(Promise.resolve({
chosenTemplateName: 'create-react-app',
componentFolder: 'src',
}) as any)

await initComponentTesting({ config: {}, cypressConfigPath: '/', useYarn: true })
expect(
someOfSpyCallsIncludes(global.console.log, 'https://github.com/cypress-io/cypress/tree/develop/npm/react/examples/react-scripts'),
).to.be.true
})

it('suggests right docs example and cypress.json config based on the `componentFolder` answer', async () => {
mockFs({
'/cypress.json': '{}',
'/package.json': JSON.stringify({
dependencies: {
react: '^16.0.0',
},
}),
})

sinon.stub(inquirer, 'prompt').returns(Promise.resolve({
chosenTemplateName: 'create-react-app',
componentFolder: 'cypress/component',
}) as any)

await initComponentTesting({ config: {}, cypressConfigPath: '/', useYarn: true })

const expectedCode = highlight(
JSON.stringify(
{
experimentalComponentTesting: true,
componentFolder: 'cypress/component',
testFiles: '**/*.spec.{js,ts,jsx,tsx}',
},
null,
2,
),
{ language: 'json' },
)

expect(global.console.log).to.be.calledWith(`\n${expectedCode}\n`)
})
})
Loading