Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: add env variable to force scaffolding #7558

Merged
merged 3 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,51 @@ jobs:
echo "console.log('hello world')" > hello.ts
npx tsc hello.ts --noEmit

# testing scaffolding examples and running them
# against example.cypress.io
test-cypress-scaffold:
parameters:
executor:
description: Executor name to use
type: executor
default: cy-doc
wd:
description: Working directory, should be OUTSIDE cypress monorepo folder
type: string
default: /root/test-scaffold
<<: *defaults
steps:
- attach_workspace:
at: ~/
# make sure we have cypress.zip received
- run: ls -l
- run: ls -l cypress.zip cypress.tgz
- run: mkdir << parameters.wd >>
- run: node --version
- run: npm --version
- run:
name: Create new NPM package ⚗️
working_directory: << parameters.wd >>
command: npm init -y
- run:
name: Install dependencies 📦
working_directory: << parameters.wd >>
environment:
CYPRESS_INSTALL_BINARY: /root/cypress/cypress.zip
# let's install Cypress, Jest and any other package that might conflict
# https://github.com/cypress-io/cypress/issues/6690
command: |
npm install /root/cypress/cypress.tgz \
typescript jest @types/jest enzyme @types/enzyme
- run:
name: Scaffold and test examples 🏗
working_directory: << parameters.wd >>
environment:
CYPRESS_INTERNAL_FORCE_SCAFFOLD: '1'
command: |
echo '{}' > cypress.json
npx cypress run

test-full-typescript-project:
parameters:
executor:
Expand Down Expand Up @@ -1457,6 +1502,10 @@ linux-workflow: &linux-workflow
requires:
- build-binary
- build-npm-package
- test-cypress-scaffold:
requires:
- build-binary
- build-npm-package
- test-full-typescript-project:
requires:
- build-binary
Expand Down
15 changes: 12 additions & 3 deletions packages/server/lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,20 @@ class Project extends EE {
// and example support file if dir doesnt exist
push(scaffold.support(cfg.supportFolder, cfg))

// if we're in headed mode add these other scaffolding
// tasks
if (!cfg.isTextTerminal) {
// if we're in headed mode add these other scaffolding tasks
debug('scaffold flags %o', {
isTextTerminal: cfg.isTextTerminal,
CYPRESS_INTERNAL_FORCE_SCAFFOLD: process.env.CYPRESS_INTERNAL_FORCE_SCAFFOLD,
})

const scaffoldExamples = !cfg.isTextTerminal || process.env.CYPRESS_INTERNAL_FORCE_SCAFFOLD

if (scaffoldExamples) {
debug('will scaffold integration and fixtures folder')
jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved
push(scaffold.integration(cfg.integrationFolder, cfg))
push(scaffold.fixture(cfg.fixturesFolder, cfg))
} else {
debug('will not scaffold integration or fixtures folder')
jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved
}

return Promise.all(scaffolds)
Expand Down
49 changes: 49 additions & 0 deletions packages/server/test/unit/project_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require('../spec_helper')

const mockedEnv = require('mocked-env')
const path = require('path')
const commitInfo = require('@cypress/commit-info')
const tsnode = require('ts-node')
Expand Down Expand Up @@ -468,6 +469,54 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
expect(scaffold.plugins).not.to.be.called
})
})

bahmutov marked this conversation as resolved.
Show resolved Hide resolved
describe('forced', () => {
let resetEnv

beforeEach(function () {
this.obj.isTextTerminal = true
resetEnv = mockedEnv({
CYPRESS_INTERNAL_FORCE_SCAFFOLD: '1',
})
})

afterEach(() => {
resetEnv()
})

it('calls scaffold when forced by environment variable', function () {
return this.project.scaffold(this.obj).then(() => {
expect(scaffold.integration).to.be.calledWith(this.obj.integrationFolder)
expect(scaffold.fixture).to.be.calledWith(this.obj.fixturesFolder)
expect(scaffold.support).to.be.calledWith(this.obj.supportFolder)
})
})
})

describe('not forced', () => {
let resetEnv

beforeEach(function () {
this.obj.isTextTerminal = true

resetEnv = mockedEnv({
CYPRESS_INTERNAL_FORCE_SCAFFOLD: undefined,
})
})

afterEach(() => {
resetEnv()
})

it('does not scaffold integration folder', function () {
return this.project.scaffold(this.obj).then(() => {
expect(scaffold.integration).to.not.be.calledWith(this.obj.integrationFolder)
expect(scaffold.fixture).to.not.be.calledWith(this.obj.fixturesFolder)
// still scaffolds support folder due to old logic
expect(scaffold.support).to.be.calledWith(this.obj.supportFolder)
})
})
})
})

context('#watchSettings', () => {
Expand Down