Skip to content

Commit

Permalink
internal: add env variable to force scaffolding (#7558)
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov authored Jun 3, 2020
1 parent fbb6c42 commit 3b40f74
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 3 deletions.
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')
push(scaffold.integration(cfg.integrationFolder, cfg))
push(scaffold.fixture(cfg.fixturesFolder, cfg))
} else {
debug('will not scaffold integration or fixtures folder')
}

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
})
})

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

4 comments on commit 3b40f74

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3b40f74 Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/linux-x64/circle-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-347172/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/circle-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-347155/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3b40f74 Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-x64/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.7.1/win32-x64/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-x64/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-x64/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3b40f74 Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-ia32/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.7.1/win32-ia32/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-ia32/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-ia32/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-33292629/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3b40f74 Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/darwin-x64/circle-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-347184/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/circle-develop-3b40f74d86b14498c92ea0b0091314094b54c3d7-347180/cypress.tgz

Please sign in to comment.