Skip to content

Commit

Permalink
remove npmInstall logic in helper/e2e script, force custom reporters …
Browse files Browse the repository at this point in the history
…to use our mocha
  • Loading branch information
kuceb committed Apr 6, 2020
1 parent 1098467 commit 33ec46b
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/server/__snapshots__/8_reporters_spec.coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ exports['e2e reporters supports teamcity reporter and reporter options 1'] = `
##teamcity[testStarted name='passes' captureStandardOutput='true' flowId='12345']
##teamcity[testFinished name='passes' duration='XXXX' flowId='12345']
##teamcity[testSuiteFinished name='simple passing spec' duration='XXXX' flowId='12345']
##teamcity[testSuiteFinished name='top suite' flowId='12345']
##teamcity[testSuiteFinished name='top suite' duration='XXXX' flowId='12345']
(Results)
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
}
}
17 changes: 16 additions & 1 deletion packages/server/lib/reporter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@ _ = require("lodash")
path = require("path")
## 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 Down
4 changes: 4 additions & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"minimatch": "3.0.4",
"minimist": "1.2.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 @@ -165,6 +166,9 @@
"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",
Expand Down
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
7 changes: 4 additions & 3 deletions packages/server/test/e2e/8_reporters_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mochaAwesomes = [
]

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

it "reports error if cannot load reporter", ->
e2e.exec(@, {
Expand Down Expand Up @@ -74,7 +74,8 @@ 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"
Expand All @@ -93,7 +94,7 @@ 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"version": "0.0.0",
"devDependencies": {
"mocha": "^4.1.0",
"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",
"react": "15.4.0"
}
}
27 changes: 4 additions & 23 deletions packages/server/test/support/helpers/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,29 +375,10 @@ const e2e = {
},

setup (options = {}) {
const npmI = options.npmInstall

if (npmI) {
before(async function () {
// npm install needs extra time
this.timeout(human('2 minutes'))

await cp.execAsync('npm install', {
cwd: Fixtures.path('projects/e2e'),
maxBuffer: 1024 * 1000,
})

// symlinks mess up fs.copySync
// and bin files aren't necessary for these tests
await fs.removeAsync(Fixtures.path('projects/e2e/node_modules/.bin'))
})

// now cleanup the node modules after because these add a lot
// of copy time for the Fixtures scaffolding
after(() => {
return fs.removeAsync(Fixtures.path('projects/e2e/node_modules'))
})
}
// cleanup old node_modules that may have been around from legacy tests
before(() => {
return fs.removeAsync(Fixtures.path('projects/e2e/node_modules'))
})

beforeEach(async function () {
// after installing node modules copying all of the fixtures
Expand Down
Loading

0 comments on commit 33ec46b

Please sign in to comment.