Merge branch 'develop' of github.com:cypress-io/cypress into md-10.0-merge

This commit is contained in:
Bill Glesias
2022-05-02 13:34:28 -04:00
2 changed files with 48 additions and 12 deletions

View File

@@ -21,6 +21,10 @@ async function checkCanaries () {
const circleEnv = await readCircleEnv()
if (Object.keys(circleEnv).length === 0) {
return console.warn('CircleCI env empty, assuming this is a contributor PR. Not checking for canary variables.')
}
if (!circleEnv.MAIN_CANARY) throw new Error('Missing MAIN_CANARY.')
if (!circleEnv.CONTEXT_CANARY) throw new Error('Missing CONTEXT_CANARY. Does this job have the test-runner:env-canary context?')
@@ -36,7 +40,12 @@ async function readCircleEnv () {
// if this starts failing, try SSHing into a CircleCI job and see what changed in the $CIRCLE_INTERNAL_CONFIG file's schema
const circleEnv = taskData['Dispatched']['TaskInfo']['Environment']
if (!circleEnv || !Object.keys(circleEnv).length) throw new Error('An empty Environment object was found.')
if (!circleEnv) throw new Error('No Environment object was found.')
// last-ditch effort to check that an empty circle env is accurately reflecting process.env (external PRs)
if (process.env.CACHE_VERSION && Object.keys(circleEnv).length === 0) {
throw new Error('CACHE_VERSION is set, but circleEnv is empty')
}
return circleEnv
} catch (err) {

View File

@@ -12,22 +12,49 @@ describe('circle-env', () => {
})
beforeEach(() => {
delete process.env.CACHE_VERSION
process.env.CI = 'true'
process.env.CIRCLE_INTERNAL_CONFIG = '/foo.json'
})
it('fails with missing canaries', async () => {
sinon.stub(fs, 'readFile')
.withArgs('/foo.json').resolves(JSON.stringify({
Dispatched: { TaskInfo: { Environment: { somekey: 'someval' } } },
}))
context('with missing canaries', () => {
it('fails', async () => {
sinon.stub(fs, 'readFile')
.withArgs('/foo.json').resolves(JSON.stringify({
Dispatched: { TaskInfo: { Environment: { somekey: 'someval' } } },
}))
try {
await _checkCanaries()
throw new Error('should not reach')
} catch (err) {
expect(err.message).to.include('Missing MAIN_CANARY')
}
try {
await _checkCanaries()
throw new Error('should not reach')
} catch (err) {
expect(err.message).to.include('Missing MAIN_CANARY')
}
})
context('with no circleEnv', () => {
beforeEach(() => {
sinon.stub(fs, 'readFile')
.withArgs('/foo.json').resolves(JSON.stringify({
Dispatched: { TaskInfo: { Environment: {} } },
}))
})
it('passes', async () => {
await _checkCanaries()
})
it('fails if CACHE_VERSION does exist', async () => {
process.env.CACHE_VERSION = 'foo'
try {
await _checkCanaries()
throw new Error('should not reach')
} catch (err) {
expect(err.message).to.include('CACHE_VERSION is set, but circleEnv is empty')
}
})
})
})
it('passes with canaries', async () => {