mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-23 23:49:43 -05:00
b0c0eaa508
Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com> Co-authored-by: Zach Bloomquist <git@chary.us> Co-authored-by: Tyler Biethman <tbiethman@users.noreply.github.com> Co-authored-by: Matt Henkes <mjhenkes@gmail.com> Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com> Co-authored-by: Matt Schile <mschile@cypress.io> Co-authored-by: Mark Noonan <mark@cypress.io> Co-authored-by: Zachary Williams <ZachJW34@gmail.com> Co-authored-by: Ben M <benm@cypress.io> Co-authored-by: Zachary Williams <zachjw34@gmail.com> Co-authored-by: astone123 <adams@cypress.io> Co-authored-by: Bill Glesias <bglesias@gmail.com> Co-authored-by: Emily Rohrbough <emilyrohrbough@yahoo.com> Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com> Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net> Co-authored-by: Adam Stone <adams@cypress.io> Co-authored-by: Blue F <blue@cypress.io> Co-authored-by: GitStart <1501599+gitstart@users.noreply.github.com> Co-authored-by: Mike Plummer <mike-plummer@users.noreply.github.com> Co-authored-by: Jordan <jordan@jpdesigning.com> Co-authored-by: Sam Goodger <turbo@tailz.dev> Co-authored-by: Colum Ferry <cferry09@gmail.com> Co-authored-by: Stokes Player <stokes@cypress.io> Co-authored-by: Vilhelm Melkstam <vilhelm.melkstam@gmail.com> Co-authored-by: amehta265 <65267668+amehta265@users.noreply.github.com>
82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
const fs = require('fs').promises
|
|
const sinon = require('sinon')
|
|
const { expect } = require('chai')
|
|
const { verifyMochaResults } = require('../verify-mocha-results')
|
|
|
|
if (process.platform !== 'win32') {
|
|
describe('verify-mocha-results', () => {
|
|
let cachedEnv = { ...process.env }
|
|
|
|
afterEach(() => {
|
|
sinon.restore()
|
|
Object.assign(process.env, cachedEnv)
|
|
})
|
|
|
|
beforeEach(() => {
|
|
process.env.CIRCLE_INTERNAL_CONFIG = '/foo.json'
|
|
sinon.stub(fs, 'readFile')
|
|
.withArgs('/foo.json').resolves(JSON.stringify({
|
|
Dispatched: { TaskInfo: { Environment: { somekey: 'someval' } } },
|
|
}))
|
|
|
|
sinon.stub(fs, 'readdir').withArgs('/tmp/cypress/junit').resolves([
|
|
'report.xml',
|
|
])
|
|
})
|
|
|
|
it('does not fail with normal report', async () => {
|
|
fs.readFile
|
|
.withArgs('/tmp/cypress/junit/report.xml')
|
|
.resolves('<testsuites name="foo" time="1" tests="10" failures="0">')
|
|
|
|
await verifyMochaResults()
|
|
})
|
|
|
|
context('env checking', () => {
|
|
it('checks for protected env and fails and removes results when found', async () => {
|
|
const spy = sinon.stub(fs, 'rm').withArgs('/tmp/cypress/junit', { recursive: true, force: true })
|
|
|
|
fs.readFile
|
|
.withArgs('/tmp/cypress/junit/report.xml')
|
|
.resolves('<testsuites name="foo" time="1" tests="10" failures="0">someval')
|
|
|
|
try {
|
|
await verifyMochaResults()
|
|
throw new Error('should not reach')
|
|
} catch (err) {
|
|
expect(err.message).to.include('somekey').and.not.include('someval')
|
|
expect(spy.getCalls().length).to.equal(1)
|
|
}
|
|
})
|
|
})
|
|
|
|
context('test result checking', () => {
|
|
it('checks for non-passing tests and fails when found', async () => {
|
|
fs.readFile
|
|
.withArgs('/tmp/cypress/junit/report.xml')
|
|
.resolves('<testsuites name="foo" time="1" tests="10" failures="3">')
|
|
|
|
try {
|
|
await verifyMochaResults()
|
|
throw new Error('should not reach')
|
|
} catch (err) {
|
|
expect(err.message).to.include('Expected the number of failures to be equal to 0')
|
|
}
|
|
})
|
|
|
|
it('checks for 0 tests run and fails when found', async () => {
|
|
fs.readFile
|
|
.withArgs('/tmp/cypress/junit/report.xml')
|
|
.resolves('<testsuites name="foo" time="1" tests="0" failures="0">')
|
|
|
|
try {
|
|
await verifyMochaResults()
|
|
throw new Error('should not reach')
|
|
} catch (err) {
|
|
expect(err.message).to.include('Expected the total number of tests to be >0')
|
|
}
|
|
})
|
|
})
|
|
})
|
|
}
|