mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-29 03:09:53 -05:00
001a310b04
* server: pass --cwd from CLI to use when resolving relative paths for various options - remove unnecessary cwd manipulation in scripts/start * server: fixes #1159, specs are normalized into an array resolved against cwd - projectPath is now normalized against cwd as well * server: move hosts out of CLI args, keep as config only * server: convert spec array to string on module API * cli: must ref root package directly * server: fixes busted specs due to cherry pick * server: temporary fix for specs being normalized into an array * server: move around spec flattening earlier * server: pass absolute path for specs * server: revert flattening hosts into config temporarily * server: add correct relative + absolute path to spec * driver: normalize spec path against project * driver: skip flaky test for now [skip ci]
143 lines
3.6 KiB
JavaScript
143 lines
3.6 KiB
JavaScript
require('../spec_helper')
|
|
|
|
const snapshot = require('snap-shot-it')
|
|
const supportsColor = require('supports-color')
|
|
|
|
const util = require(`${lib}/util`)
|
|
const logger = require(`${lib}/logger`)
|
|
|
|
describe('util', function () {
|
|
beforeEach(function () {
|
|
this.sandbox.stub(process, 'exit')
|
|
this.sandbox.stub(logger, 'error')
|
|
})
|
|
|
|
context('.stdoutLineMatches', () => {
|
|
const { stdoutLineMatches } = util
|
|
|
|
it('is a function', () => {
|
|
expect(stdoutLineMatches).to.be.a.function
|
|
})
|
|
|
|
it('matches entire output', () => {
|
|
const line = '444'
|
|
expect(stdoutLineMatches(line, line)).to.be.true
|
|
})
|
|
|
|
it('matches a line in output', () => {
|
|
const line = '444'
|
|
const stdout = ['start', line, 'something else'].join('\n')
|
|
expect(stdoutLineMatches(line, stdout)).to.be.true
|
|
})
|
|
|
|
it('matches a trimmed line in output', () => {
|
|
const line = '444'
|
|
const stdout = ['start', ` ${line} `, 'something else'].join('\n')
|
|
expect(stdoutLineMatches(line, stdout)).to.be.true
|
|
})
|
|
|
|
it('does not find match', () => {
|
|
const line = '445'
|
|
const stdout = ['start', '444', 'something else'].join('\n')
|
|
expect(stdoutLineMatches(line, stdout)).to.be.false
|
|
})
|
|
})
|
|
|
|
context('.normalizeModuleOptions', () => {
|
|
const { normalizeModuleOptions } = util
|
|
|
|
it('does not change other properties', () => {
|
|
const options = {
|
|
foo: 'bar',
|
|
}
|
|
snapshot('others_unchanged', normalizeModuleOptions(options))
|
|
})
|
|
|
|
it('passes string env unchanged', () => {
|
|
const options = {
|
|
env: 'foo=bar',
|
|
}
|
|
snapshot('env_as_string', normalizeModuleOptions(options))
|
|
})
|
|
|
|
it('converts environment object', () => {
|
|
const options = {
|
|
env: {
|
|
foo: 'bar',
|
|
magicNumber: 1234,
|
|
host: 'kevin.dev.local',
|
|
},
|
|
}
|
|
snapshot('env_as_object', normalizeModuleOptions(options))
|
|
})
|
|
|
|
it('converts config object', () => {
|
|
const options = {
|
|
config: {
|
|
baseUrl: 'http://localhost:2000',
|
|
watchForFileChanges: false,
|
|
},
|
|
}
|
|
snapshot('config_as_object', normalizeModuleOptions(options))
|
|
})
|
|
|
|
it('converts reporterOptions object', () => {
|
|
const options = {
|
|
reporterOptions: {
|
|
mochaFile: 'results/my-test-output.xml',
|
|
toConsole: true,
|
|
},
|
|
}
|
|
snapshot('reporter_options_as_object', normalizeModuleOptions(options))
|
|
})
|
|
|
|
it('converts specs array', () => {
|
|
const options = {
|
|
spec: [
|
|
'a', 'b', 'c',
|
|
],
|
|
}
|
|
snapshot('spec_as_array', normalizeModuleOptions(options))
|
|
})
|
|
|
|
it('does not convert spec when string', () => {
|
|
const options = {
|
|
spec: 'x,y,z',
|
|
}
|
|
snapshot('spec_as_string', normalizeModuleOptions(options))
|
|
})
|
|
})
|
|
|
|
context('.supportsColor', function () {
|
|
it('is true on obj return for stderr', function () {
|
|
const obj = {}
|
|
this.sandbox.stub(supportsColor, 'stderr').value(obj)
|
|
|
|
expect(util.supportsColor()).to.be.true
|
|
})
|
|
|
|
it('is false on false return for stderr', function () {
|
|
this.sandbox.stub(supportsColor, 'stderr').value(false)
|
|
|
|
expect(util.supportsColor()).to.be.false
|
|
})
|
|
})
|
|
|
|
it('.exit', function () {
|
|
util.exit(2)
|
|
expect(process.exit).to.be.calledWith(2)
|
|
|
|
util.exit(0)
|
|
expect(process.exit).to.be.calledWith(0)
|
|
})
|
|
|
|
it('.logErrorExit1', function () {
|
|
const err = new Error('foo')
|
|
|
|
util.logErrorExit1(err)
|
|
|
|
expect(process.exit).to.be.calledWith(1)
|
|
expect(logger.error).to.be.calledWith('foo')
|
|
})
|
|
})
|