WIP: rename all the specs, move them around, get it going!

This commit is contained in:
Brian Mann
2017-09-04 00:16:59 -04:00
parent 4842c9d6a4
commit 77ea4fc5c2
16 changed files with 137 additions and 131 deletions
+3 -3
View File
@@ -56,7 +56,7 @@ returned:
Error: Smoke test returned wrong code.
command was: /Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/dist/Cypress.app/Contents/MacOS/Cypress --smoke-test --ping=187
returned:
at child.on (/Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/lib/download/utils.js:153:27)
at child.on (/Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/lib/tasks/verify.js:153:27)
at /Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/node_modules/sinon/lib/sinon/behavior.js:92:22
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
@@ -105,7 +105,7 @@ returned:
Error: Smoke test returned wrong code.
command was: /Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/dist/Cypress.app/Contents/MacOS/Cypress --smoke-test --ping=7
returned:
at child.on (/Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/lib/download/utils.js:153:27)
at child.on (/Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/lib/tasks/verify.js:153:27)
at /Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/node_modules/sinon/lib/sinon/behavior.js:92:22
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
@@ -153,7 +153,7 @@ returned:
Error: Smoke test returned wrong code.
command was: /Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/dist/Cypress.app/Contents/MacOS/Cypress --smoke-test --ping=733
returned:
at child.on (/Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/lib/download/utils.js:153:27)
at child.on (/Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/lib/tasks/verify.js:153:27)
at /Users/chrisbreiding/Dev/cypress/cypress-monorepo/cli/node_modules/sinon/lib/sinon/behavior.js:92:22
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
+3
View File
@@ -1,4 +1,7 @@
{
"globals": {
"lib": true
},
"extends": [
"plugin:cypress-dev/tests"
]
-45
View File
@@ -1,45 +0,0 @@
require('./spec_helper')
const cli = require('../lib/cli')
const download = require('../lib/download')
const downloadUtils = require('../lib/download/utils')
const run = require('../lib/exec/run')
const open = require('../lib/exec/open')
describe('cli', function () {
beforeEach(function () {
this.sandbox.stub(process, 'exit')
this.exec = (args) => cli.init().parse(`node test ${args}`.split(' '))
})
it('exits when done', function (done) {
this.sandbox.stub(run, 'start').resolves()
this.exec('run --port 7878')
process.exit.callsFake(done)
})
it('run calls run#start with options', function () {
this.sandbox.stub(run, 'start').resolves()
this.exec('run --port 7878')
expect(run.start).to.be.calledWith({ port: '7878' })
})
it('open calls open#start with options', function () {
this.sandbox.stub(open, 'start')
this.exec('open --port 7878')
expect(open.start).to.be.calledWith({ port: '7878' })
})
it('install calls download#install with force: true', function () {
this.sandbox.stub(download, 'install')
this.exec('install')
expect(download.install).to.be.calledWith({ force: true })
})
it('verify calls downloadUtils#verify with force: true', function () {
this.sandbox.stub(downloadUtils, 'verify')
this.exec('verify')
expect(downloadUtils.verify).to.be.calledWith({ force: true })
})
})
+45
View File
@@ -0,0 +1,45 @@
require('../spec_helper')
const cli = require(`${lib}/cli`)
const run = require(`${lib}/exec/run`)
const open = require(`${lib}/exec/open`)
const verify = require(`${lib}/tasks/verify`)
const install = require(`${lib}/tasks/install`)
describe('cli', function () {
beforeEach(function () {
this.sandbox.stub(process, 'exit')
this.exec = (args) => cli.init().parse(`node test ${args}`.split(' '))
})
it('exits when done', function (done) {
this.sandbox.stub(run, 'start').resolves()
this.exec('run --port 7878')
process.exit.callsFake(done)
})
it('run calls run.start with options', function () {
this.sandbox.stub(run, 'start').resolves()
this.exec('run --port 7878')
expect(run.start).to.be.calledWith({ port: '7878' })
})
it('open calls open.start with options', function () {
this.sandbox.stub(open, 'start').resolves()
this.exec('open --port 7878')
expect(open.start).to.be.calledWith({ port: '7878' })
})
it('install calls install.start with force: true', function () {
this.sandbox.stub(install, 'start').resolves()
this.exec('install')
expect(install.start).to.be.calledWith({ force: true })
})
it('verify calls verify.start with force: true', function () {
this.sandbox.stub(verify, 'start').resolves()
this.exec('verify')
expect(verify.start).to.be.calledWith({ force: true })
})
})
@@ -1,14 +1,14 @@
require('./spec_helper')
require('../spec_helper')
const os = require('os')
const path = require('path')
const Promise = require('bluebird')
const tmp = Promise.promisifyAll(require('tmp'))
const fs = require('../lib/fs')
const open = require('../lib/exec/open')
const run = require('../lib/exec/run')
const cypress = require('../lib/cypress')
const fs = require(`${lib}/fs`)
const open = require(`${lib}/exec/open`)
const run = require(`${lib}/exec/run`)
const cypress = require(`${lib}/cypress`)
describe('cypress', function () {
context('#open', function () {
@@ -1,7 +1,7 @@
require('../spec_helper')
const os = require('os')
const { errors, formError, formErrorText } = require('../../lib/errors')
const { errors, formError, formErrorText } = require(`${lib}/errors`)
const snapshot = require('snap-shot-it')
const { omit } = require('ramda')
@@ -1,11 +1,11 @@
require('../spec_helper')
require('../../spec_helper')
const downloadUtils = require('../../lib/download/utils')
const spawn = require('../../lib/exec/spawn')
const open = require('../../lib/exec/open')
const util = require('../../lib/util')
const logger = require('../../lib/logger')
const fs = require('../../lib/fs')
const verify = require(`${lib}/tasks/verify`)
const spawn = require(`${lib}/exec/spawn`)
const open = require(`${lib}/exec/open`)
const util = require(`${lib}/util`)
const logger = require(`${lib}/logger`)
const fs = require(`${lib}/fs`)
const snapshot = require('snap-shot-it')
describe('exec open', function () {
@@ -30,13 +30,13 @@ describe('exec open', function () {
context('#start', function () {
beforeEach(function () {
this.sandbox.stub(util, 'isInstalledGlobally').returns(true)
this.sandbox.stub(downloadUtils, 'verify').resolves()
this.sandbox.stub(verify, 'verify').resolves()
this.sandbox.stub(spawn, 'start').resolves()
})
it('verifies download', function () {
return open.start().then(() => {
expect(downloadUtils.verify).to.be.called
expect(verify.verify).to.be.called
})
})
@@ -1,12 +1,12 @@
require('../spec_helper')
require('../../spec_helper')
const downloadUtils = require('../../lib/download/utils')
const cli = require('../../lib/cli')
const spawn = require('../../lib/exec/spawn')
const run = require('../../lib/exec/run')
const verify = require(`${lib}/tasks/verify`)
const cli = require(`${lib}/cli`)
const spawn = require(`${lib}/exec/spawn`)
const run = require(`${lib}/exec/run`)
const snapshot = require('snap-shot-it')
const util = require('../../lib/util')
const logger = require('../../lib/logger')
const util = require(`${lib}/util`)
const logger = require(`${lib}/logger`)
describe('exec run', function () {
beforeEach(function () {
@@ -88,14 +88,14 @@ describe('exec run', function () {
context('#start', function () {
beforeEach(function () {
this.sandbox.stub(spawn, 'start')
this.sandbox.stub(downloadUtils, 'verify').resolves()
this.sandbox.stub(verify, 'verify').resolves()
this.log = this.sandbox.spy(logger, 'log')
})
it('verifies cypress', function () {
return run.start()
.then(() => {
expect(downloadUtils.verify).to.be.calledOnce
expect(verify.verify).to.be.calledOnce
})
})
@@ -1,10 +1,10 @@
require('../spec_helper')
require('../../spec_helper')
const cp = require('child_process')
const downloadUtils = require('../../lib/download/utils')
const xvfb = require('../../lib/exec/xvfb')
const spawn = require('../../lib/exec/spawn')
const verify = require(`${lib}/tasks/verify`)
const xvfb = require(`${lib}/exec/xvfb`)
const spawn = require(`${lib}/exec/spawn`)
describe('exec spawn', function () {
beforeEach(function () {
@@ -17,7 +17,7 @@ describe('exec spawn', function () {
this.sandbox.stub(xvfb, 'start').resolves()
this.sandbox.stub(xvfb, 'stop').resolves()
this.sandbox.stub(xvfb, 'isNeeded').returns(true)
this.sandbox.stub(downloadUtils, 'getPathToExecutable').returns('/path/to/cypress')
this.sandbox.stub(verify, 'getPathToExecutable').returns('/path/to/cypress')
})
context('#spawn', function () {
@@ -1,7 +1,7 @@
require('../spec_helper')
require('../../spec_helper')
const os = require('os')
const xvfb = require('../../lib/exec/xvfb')
const xvfb = require(`${lib}/exec/xvfb`)
describe('exec xvfb', function () {
context('#start', function () {
@@ -1,15 +1,15 @@
require('../spec_helper')
require('../../spec_helper')
const nock = require('nock')
const path = require('path')
const snapshot = require('snap-shot-it')
const fs = require('../../lib/fs')
const download = require('../../lib/download/download')
const logger = require('../../lib/logger')
const unzip = require('../../lib/download/unzip')
const downloadUtils = require('../../lib/download/utils')
const util = require('../../lib/util')
const fs = require(`${lib}/fs`)
const download = require(`${lib}/tasks/download`)
const logger = require(`${lib}/logger`)
const unzip = require(`${lib}/tasks/unzip`)
const verify = require(`${lib}/tasks/verify`)
const util = require(`${lib}/util`)
describe('download', function () {
const rootFolder = '/home/user/git'
@@ -71,7 +71,7 @@ describe('download', function () {
// not really the download erroring, but the easiest way to
// test the error handling
this.sandbox.stub(downloadUtils, 'ensureInstallationDir').rejects(err)
this.sandbox.stub(verify, 'ensureInstallationDir').rejects(err)
return download.start(this.options).then(() => {
expect(util.exit).to.be.calledWith(1)
@@ -125,7 +125,7 @@ describe('download', function () {
})
it('logs out Finished Installing', function () {
this.sandbox.stub(downloadUtils, 'getPathToUserExecutable').returns('/foo/bar')
this.sandbox.stub(verify, 'getPathToUserExecutableDir').returns('/foo/bar')
return download.start(this.options)
.then(() => {
@@ -135,7 +135,7 @@ describe('download', function () {
it('the reported path is relative', function () {
const appAt = 'node_modules/cypress/dist/Cypress.app'
this.sandbox.stub(downloadUtils, 'getPathToUserExecutable')
this.sandbox.stub(verify, 'getPathToUserExecutableDir')
.returns(path.join(rootFolder, appAt))
return download.start(this.options)
@@ -1,17 +1,18 @@
require('../spec_helper')
require('../../spec_helper')
const chalk = require('chalk')
const fs = require('../../lib/fs')
const download = require('../../lib/download/download')
const index = require('../../lib/download/index')
const utils = require('../../lib/download/utils')
const unzip = require('../../lib/download/unzip')
const logger = require('../../lib/logger')
const fs = require(`${lib}/fs`)
const download = require(`${lib}/tasks/download`)
const install = require(`${lib}/tasks/install`)
const info = require(`${lib}/tasks/info`)
const unzip = require(`${lib}/tasks/unzip`)
const logger = require(`${lib}/logger`)
const util = require(`${lib}/util`)
const packageVersion = require('../../package').version
const packageVersion = util.pkgVersion()
describe('index', function () {
describe('install', function () {
beforeEach(() => {
// allow simpler log message comparison without
// chalk's terminal control strings
@@ -22,13 +23,13 @@ describe('index', function () {
chalk.enabled = true
})
context('#install', function () {
context('.start', function () {
beforeEach(function () {
this.sandbox.stub(logger, 'log')
this.sandbox.stub(download, 'start').resolves()
this.sandbox.stub(utils, 'getInstalledVersion').resolves()
this.sandbox.stub(utils, 'writeInstalledVersion').resolves()
this.sandbox.stub(utils, 'clearVersionState').resolves()
this.sandbox.stub(info, 'getInstalledVersion').resolves()
this.sandbox.stub(info, 'writeInstalledVersion').resolves()
this.sandbox.stub(info, 'clearVersionState').resolves()
})
describe('override version', function () {
@@ -40,7 +41,7 @@ describe('index', function () {
const version = '0.12.1'
process.env.CYPRESS_VERSION = version
return index.install()
return install.install()
.then(() => {
const msg = `Forcing CYPRESS_VERSION ${version}`
expect(logger.log.calledWith(msg)).to.be.true
@@ -58,22 +59,22 @@ describe('index', function () {
this.sandbox.stub(fs, 'statAsync').withArgs(version).resolves()
this.sandbox.stub(unzip, 'start').resolves()
return index.install()
return install.start()
.then(() => {
expect(unzip.start).calledWith({
zipDestination: version,
destination: utils.getInstallationDir(),
executable: utils.getPathToUserExecutable(),
destination: info.getInstallationDir(),
executable: info.getPathToUserExecutableDir(),
})
expect(utils.writeInstalledVersion).calledWith('unknown')
expect(info.writeInstalledVersion).calledWith('unknown')
})
})
})
describe('when version is already installed', function () {
beforeEach(function () {
utils.getInstalledVersion.resolves(packageVersion)
return index.install()
info.getInstalledVersion.resolves(packageVersion)
return install.start()
})
it('logs message', function () {
@@ -88,8 +89,8 @@ describe('index', function () {
describe('when getting installed version fails', function () {
beforeEach(function () {
utils.getInstalledVersion.rejects(new Error('no'))
return index.install()
info.getInstalledVersion.rejects(new Error('no'))
return install.start()
})
it('logs message', function () {
@@ -108,8 +109,8 @@ describe('index', function () {
describe('when getting installed version does not match needed version', function () {
beforeEach(function () {
utils.getInstalledVersion.resolves('x.x.x')
return index.install()
info.getInstalledVersion.resolves('x.x.x')
return install.start()
})
it('logs message', function () {
@@ -130,12 +131,12 @@ describe('index', function () {
describe('with force: true', function () {
beforeEach(function () {
utils.getInstalledVersion.resolves(packageVersion)
return index.install({ force: true })
info.getInstalledVersion.resolves(packageVersion)
return install.start({ force: true })
})
it('clears version state', function () {
expect(utils.clearVersionState).to.be.called
expect(info.clearVersionState).to.be.called
})
it('forces download even if version matches', function () {
@@ -1,9 +1,9 @@
require('../spec_helper')
require('../../spec_helper')
const path = require('path')
const fs = require('../../lib/fs')
const unzip = require('../../lib/download/unzip')
const fs = require(`${lib}/fs`)
const unzip = require(`${lib}/tasks/unzip`)
describe('unzip', function () {
context('#cleanup', () =>
@@ -1,4 +1,4 @@
require('../spec_helper')
require('../../spec_helper')
const _ = require('lodash')
const os = require('os')
@@ -8,11 +8,11 @@ const cp = require('child_process')
const clearModule = require('clear-module')
const snapshot = require('snap-shot-it')
const fs = require('../../lib/fs')
const logger = require('../../lib/logger')
const utils = require('../../lib/download/utils')
const xvfb = require('../../lib/exec/xvfb')
const packageVersion = require('../../lib/util').pkgVersion()
const fs = require(`${lib}/fs`)
const logger = require(`${lib}/logger`)
const utils = require(`${lib}/tasks/verify`)
const xvfb = require(`${lib}/exec/xvfb`)
const packageVersion = require(`${lib}/util`).pkgVersion()
const distDir = path.join(__dirname, '../../dist')
const infoFilePath = path.join(distDir, 'info.json')
@@ -142,20 +142,20 @@ describe('utils', function () {
})
})
context('#getPathToUserExecutable', function () {
context('#getPathToUserExecutableDir', function () {
it('resolves path on macOS', function () {
this.sandbox.stub(os, 'platform').returns('darwin')
expect(utils.getPathToUserExecutable()).to.equal(path.join(distDir, 'Cypress.app'))
expect(utils.getPathToUserExecutableDir()).to.equal(path.join(distDir, 'Cypress.app'))
})
it('resolves path on linux', function () {
this.sandbox.stub(os, 'platform').returns('linux')
expect(utils.getPathToUserExecutable()).to.equal(path.join(distDir, 'Cypress'))
expect(utils.getPathToUserExecutableDir()).to.equal(path.join(distDir, 'Cypress'))
})
it('rejects on anything else', function () {
this.sandbox.stub(os, 'platform').returns('win32')
expect(() => utils.getPathToUserExecutable()).to.throw('Platform: "win32" is not supported.')
expect(() => utils.getPathToUserExecutableDir()).to.throw('Platform: "win32" is not supported.')
})
})
View File
+4 -2
View File
@@ -1,7 +1,9 @@
global.expect = require('chai').expect
global.Promise = require('bluebird')
const path = require('path')
const sinon = require('sinon')
global.expect = require('chai').expect
global.lib = path.join(__dirname, '..', 'lib')
require('chai')
.use(require('@cypress/sinon-chai'))