diff --git a/circle.yml b/circle.yml index 894919c4a223..8126933b676f 100644 --- a/circle.yml +++ b/circle.yml @@ -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: @@ -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 diff --git a/packages/server/lib/project.js b/packages/server/lib/project.js index e56b34bbc108..40fa9c78cbed 100644 --- a/packages/server/lib/project.js +++ b/packages/server/lib/project.js @@ -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) diff --git a/packages/server/test/unit/project_spec.js b/packages/server/test/unit/project_spec.js index 982272fd2961..be4865e24531 100644 --- a/packages/server/test/unit/project_spec.js +++ b/packages/server/test/unit/project_spec.js @@ -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') @@ -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', () => {