Skip to content

Commit

Permalink
Merge branch 'server-e2e-tests-allow-watch' into fix-rerun-hooks-on-n…
Browse files Browse the repository at this point in the history
…avigation
  • Loading branch information
kuceb committed Apr 20, 2020
2 parents 5a64934 + 33ec46b commit 6c7ba0f
Show file tree
Hide file tree
Showing 22 changed files with 603 additions and 848 deletions.
5 changes: 4 additions & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
"mocha": "7.0.1",
"moment": "2.24.0",
"morgan": "1.9.1",
"npm-install-version": "6.0.2",
"react-15.6.1": "npm:react@15.6.1",
"react-16.0.0": "npm:react@16.0.0",
"react-dom-15.6.1": "npm:react-dom@15.6.1",
"react-dom-16.0.0": "npm:react-dom@16.0.0",
"setimmediate": "1.0.5",
"sinon": "8.1.1",
"text-mask-addons": "3.8.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/test/cypress/fixtures/react-15.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</head>
<body>
<div id="react-container"></div>
<script src="/node_modules/react@15.6.1/dist/react.js"></script>
<script src="/node_modules/react-dom@15.6.1/dist/react-dom.js"></script>
<script src="/node_modules/react-15.6.1/dist/react.js"></script>
<script src="/node_modules/react-dom-15.6.1/dist/react-dom.js"></script>
<script>
window.onChangeEvents = 0

Expand Down
4 changes: 2 additions & 2 deletions packages/driver/test/cypress/fixtures/react-16.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</head>
<body>
<div id="react-container"></div>
<script src="/node_modules/react@16.0.0/umd/react.development.js"></script>
<script src="/node_modules/react-dom@16.0.0/umd/react-dom.development.js"></script>
<script src="/node_modules/react-16.0.0/umd/react.development.js"></script>
<script src="/node_modules/react-dom-16.0.0/umd/react-dom.development.js"></script>
<script>
window.onChangeEvents = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe "src/cy/commands/angular", ->

describe "errors", ->
beforeEach ->
Cypress.config("defaultCommandTimeout", 50)
Cypress.config("defaultCommandTimeout", 100)

@angular = cy.state("window").angular

Expand Down Expand Up @@ -94,7 +94,7 @@ describe "src/cy/commands/angular", ->

describe "errors", ->
beforeEach ->
Cypress.config("defaultCommandTimeout", 50)
Cypress.config("defaultCommandTimeout", 100)

@angular = cy.state("window").angular

Expand Down Expand Up @@ -208,7 +208,7 @@ describe "src/cy/commands/angular", ->

describe "errors", ->
beforeEach ->
Cypress.config("defaultCommandTimeout", 50)
Cypress.config("defaultCommandTimeout", 100)

@angular = cy.state("window").angular

Expand Down
7 changes: 0 additions & 7 deletions packages/driver/test/support/server.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
_ = require("lodash")
fs = require("fs")
niv = require("npm-install-version")
auth = require("basic-auth")
bodyParser = require("body-parser")
express = require("express")
Expand All @@ -11,12 +10,6 @@ coffee = require("@packages/coffee")

args = require("minimist")(process.argv.slice(2))

## make sure we have both versions of react
niv.install("react@16.0.0")
niv.install("react-dom@16.0.0")
niv.install("react@15.6.1")
niv.install("react-dom@15.6.1")

[3500, 3501].forEach (port) ->
app = express()
server = http.Server(app)
Expand Down
5 changes: 5 additions & 0 deletions packages/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ yarn test test/e2e/1_async_timeouts_spec.coffee
yarn test-e2e 1_async ## shorthand, uses globbing to find spec
```

To keep the browser open after a spec run (for easier debugging and iterating on specs), you can pass the `--no-exit` flag to the e2e test command. Live reloading due to spec changes should also work:
```sh
yarn test test/e2e/2_go_spec.coffee --browser chrome --no-exit
```

### Updating snaphots

Prepend `SNAPSHOT_UPDATE=1` to any test command. See [`snap-shot-it` instructions](https://github.com/bahmutov/snap-shot-it#advanced-use) for more info.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports['e2e async timeouts failing1 1'] = `
exports['e2e async timeouts / failing1'] = `
====================================================================================================
Expand Down
12 changes: 6 additions & 6 deletions packages/server/__snapshots__/8_reporters_spec.coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ finished!
`

exports['e2e reporters mochawesome passes with mochawesome@1.5.2 npm custom reporter 1'] = `
exports['e2e reporters mochawesome passes with mochawesome-1.5.2 npm custom reporter 1'] = `
====================================================================================================
Expand Down Expand Up @@ -197,7 +197,7 @@ exports['e2e reporters mochawesome passes with mochawesome@1.5.2 npm custom repo
`

exports['e2e reporters mochawesome fails with mochawesome@1.5.2 npm custom reporter 1'] = `
exports['e2e reporters mochawesome fails with mochawesome-1.5.2 npm custom reporter 1'] = `
====================================================================================================
Expand Down Expand Up @@ -314,7 +314,7 @@ Because this error occurred during a \`after all\` hook we are skipping the rema
`

exports['e2e reporters mochawesome passes with mochawesome@2.3.1 npm custom reporter 1'] = `
exports['e2e reporters mochawesome passes with mochawesome-2.3.1 npm custom reporter 1'] = `
====================================================================================================
Expand Down Expand Up @@ -379,7 +379,7 @@ exports['e2e reporters mochawesome passes with mochawesome@2.3.1 npm custom repo
`

exports['e2e reporters mochawesome fails with mochawesome@2.3.1 npm custom reporter 1'] = `
exports['e2e reporters mochawesome fails with mochawesome-2.3.1 npm custom reporter 1'] = `
====================================================================================================
Expand Down Expand Up @@ -494,7 +494,7 @@ Because this error occurred during a \`after all\` hook we are skipping the rema
`

exports['e2e reporters mochawesome passes with mochawesome@3.0.1 npm custom reporter 1'] = `
exports['e2e reporters mochawesome passes with mochawesome-3.0.1 npm custom reporter 1'] = `
====================================================================================================
Expand Down Expand Up @@ -559,7 +559,7 @@ exports['e2e reporters mochawesome passes with mochawesome@3.0.1 npm custom repo
`

exports['e2e reporters mochawesome fails with mochawesome@3.0.1 npm custom reporter 1'] = `
exports['e2e reporters mochawesome fails with mochawesome-3.0.1 npm custom reporter 1'] = `
====================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ module.exports = {
delete config.envFile

## when headless
if config.isTextTerminal
if config.isTextTerminal && !process.env.CYPRESS_INTERNAL_FORCE_FILEWATCH
## dont ever watch for file changes
config.watchForFileChanges = false

Expand Down
21 changes: 21 additions & 0 deletions packages/server/lib/overrideRequire.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const Module = require('module')

export const overrideRequire = (requireOverride) => {
const _load = Module._load

Module._load = function (...args: any[]) {
let pkg = args

if (requireOverride) {
const mockedDependency = requireOverride(pkg[0], _load)

if (mockedDependency != null) {
return mockedDependency
}
}

const ret = _load.apply(this, pkg)

return ret
}
}
2 changes: 1 addition & 1 deletion packages/server/lib/plugins/preprocessor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = {
## in a text terminal aka cypress run
## TODO: rename this to config.isRunMode
## vs config.isInterativeMode
shouldWatch = not config.isTextTerminal
shouldWatch = not config.isTextTerminal || !!process.env.CYPRESS_INTERNAL_FORCE_FILEWATCH

baseFilePath = filePath
.replace(config.projectRoot, "")
Expand Down
23 changes: 20 additions & 3 deletions packages/server/lib/reporter.coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
_ = require("lodash")
path = require("path")
Mocha = require("mocha")
## mocha-* is used to allow us to have later versions of mocha specified in devDependencies
## and prevents accidently upgrading this one
## TODO: look into upgrading this to version in driver
Mocha = require("mocha-2.4.5")
mochaReporters = require("mocha-2.4.5/lib/reporters")

debug = require("debug")("cypress:server:reporter")
Promise = require("bluebird")
{overrideRequire} = require('./overrideRequire')

mochaReporters = require("mocha/lib/reporters")

mochaErrMsgExtractionRe = /^([^:]+): expected/

STATS = "suites tests passes pending failures start end duration".split(" ")

## version 4.1.0 is what we've historically ran our e2e tests against
## there is no other reason it is specifically 4.1.0
## TODO: look into upgrading to version in driver
customReporterMocha = path.dirname(require.resolve('mocha-4.1.0'))

## override calls to `require('mocha*')` when to always resolve with a mocha we control
## otherwise mocha will be resolved from project's node_modules and might not work with our code
overrideRequire((depPath, _load) ->
if depPath is 'mocha' or depPath.startsWith('mocha/')
return _load(depPath.replace('mocha', customReporterMocha))
)

if Mocha.Suite.prototype.titlePath
throw new Error('Mocha.Suite.prototype.titlePath already exists. Please remove the monkeypatch code.')

Expand All @@ -20,7 +37,7 @@ Mocha.Suite.prototype.titlePath = ->
result = result.concat(@parent.titlePath())

if !@root
result.push(@title);
result.push(@title)

return result

Expand Down
8 changes: 6 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"mime": "2.4.4",
"minimatch": "3.0.4",
"minimist": "1.2.5",
"mocha": "2.4.5",
"mocha-2.4.5": "npm:mocha@2.4.5",
"mocha-4.1.0": "npm:mocha@4.1.0",
"mocha-junit-reporter": "1.23.1",
"mocha-teamcity-reporter": "3.0.0",
"moment": "2.24.0",
Expand Down Expand Up @@ -166,12 +167,15 @@
"http-mitm-proxy": "0.7.0",
"https-proxy-agent": "3.0.1",
"istanbul": "0.4.5",
"mocha": "7.0.1",
"mochawesome-1.5.2": "npm:mochawesome@1.5.2",
"mochawesome-2.3.1": "npm:mochawesome@2.3.1",
"mochawesome-3.0.1": "npm:mochawesome@3.0.1",
"mock-fs": "4.10.4",
"mocked-env": "1.2.4",
"mockery": "2.1.0",
"multiparty": "4.2.1",
"nock": "12.0.2",
"npm-install-version": "6.0.2",
"proxyquire": "2.1.0",
"react": "15.6.2",
"repl.history": "0.1.4",
Expand Down
11 changes: 5 additions & 6 deletions packages/server/test/e2e/1_async_timeouts_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ e2e = require("../support/helpers/e2e")
describe "e2e async timeouts", ->
e2e.setup()

it "failing1", ->
e2e.exec(@, {
spec: "async_timeouts_spec.coffee"
snapshot: true
expectedExitCode: 2
})
e2e.it "failing1", {
spec: "async_timeouts_spec.coffee"
snapshot: true
expectedExitCode: 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Fixtures = require("../support/helpers/fixtures")
e2ePath = Fixtures.projectPath("e2e")

describe "e2e browserify, babel, es2015", ->
e2e.setup({npmInstall: true})
e2e.setup()

it "passes", ->
e2e.exec(@, {
Expand Down
19 changes: 9 additions & 10 deletions packages/server/test/e2e/8_reporters_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ Fixtures = require("../support/helpers/fixtures")
e2ePath = Fixtures.projectPath("e2e")

mochaAwesomes = [
"mochawesome@1.5.2"
"mochawesome@2.3.1"
"mochawesome@3.0.1"
"mochawesome-1.5.2"
"mochawesome-2.3.1"
"mochawesome-3.0.1"
]

describe "e2e reporters", ->
e2e.setup({
npmInstall: mochaAwesomes
})
e2e.setup()

it "reports error if cannot load reporter", ->
e2e.exec(@, {
Expand Down Expand Up @@ -76,10 +74,11 @@ describe "e2e reporters", ->
e2e.exec(@, {
spec: "simple_passing_spec.coffee"
snapshot: true
reporter: ma
## cypress supports passing module name, relative path, or absolute path
reporter: require.resolve(ma)
})
.then ->
if ma is "mochawesome@1.5.2"
if ma is "mochawesome-1.5.2"
fs.readFileAsync(path.join(e2ePath, "mochawesome-reports", "mochawesome.html"), "utf8")
.then (xml) ->
expect(xml).to.include("<h3 class=\"suite-title\">simple passing spec</h3>")
Expand All @@ -95,10 +94,10 @@ describe "e2e reporters", ->
spec: "simple_failing_hook_spec.coffee"
snapshot: true
expectedExitCode: 3
reporter: ma
reporter: require.resolve(ma)
})
.then ->
if ma is "mochawesome@1.5.2"
if ma is "mochawesome-1.5.2"
fs.readFileAsync(path.join(e2ePath, "mochawesome-reports", "mochawesome.html"), "utf8")
.then (xml) ->
expect(xml).to.include("<h3 class=\"suite-title\">simple failing hook spec</h3>")
Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/integration/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ describe('lib/cypress', () => {
})

it('removes fixtures when they exist and fixturesFolder is false', function (done) {
return config.get(this.idsPath)
config.get(this.idsPath)
.then((cfg) => {
this.cfg = cfg

Expand Down
9 changes: 6 additions & 3 deletions packages/server/test/scripts/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ commandAndArguments.args.push(
'--timeout',
options['inspect-brk'] ? '40000000' : '10000',
'--recursive',
'--compilers ts:@packages/ts/register,coffee:@packages/coffee/register',
'-r @packages/ts/register',
'-r @packages/coffee/register',
'--reporter',
'mocha-multi-reporters',
'--reporter-options',
'configFile=../../mocha-reporter-config.json',
// restore mocha 2.x behavior to force end process after spec run
'--exit',
)

const env = _.clone(process.env)
Expand Down Expand Up @@ -145,8 +148,8 @@ if (options.browser) {
env.BROWSER = options.browser
}

if (options.exit != null) {
env.EXIT = options.exit
if (options.exit === false) {
env.NO_EXIT = '1'
}

const cmd = `${commandAndArguments.command} ${
Expand Down
Loading

0 comments on commit 6c7ba0f

Please sign in to comment.