diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 746d7ade..b6230c9e 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -20,5 +20,7 @@ jobs: - name: Install dependencies run: npm ci --production - name: Run integration tests + env: + SAUCE_CYPRESS_VIDEO_RECORDING: false run: bash tests/integration/integration-tests.sh diff --git a/README.md b/README.md index 9a7f60e7..bf690359 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,15 @@ $ docker pull saucelabs/stt-cypress-mocha-node:latest ### Integration tests `npm run test-integration` triggers the [integration tests script](/tests/integration/integration-tests.sh). Which triggers the tests in (/tests/integration/fixtures/cypress-tests) and runs them through `cypress-runner.js`. +### Env Variables +#### `SAUCE_CYPRESS_VIDEO_RECORDING` +This env variable is for controlling cypress native video recording. +`true`/`1` will enable cypress native video recording. +`false`/`0` will stop cypress native video recording. +```sh +saucectl run -e SAUCE_CYPRESS_VIDEO_RECORDING=true +``` + ## Publishing to Docker Hub To publish the Docker image: * Create a [new release](https://github.com/saucelabs/sauce-cypress-runner/releases) diff --git a/src/cypress-runner.js b/src/cypress-runner.js index 7fcb5111..346bcd20 100644 --- a/src/cypress-runner.js +++ b/src/cypress-runner.js @@ -5,7 +5,7 @@ const { promisify } = require('util'); const yaml = require('js-yaml'); const cypress = require('cypress'); let { exec } = require('child_process'); -const { getAbsolutePath } = require('./utils'); +const { getAbsolutePath, shouldRecordVideo } = require('./utils'); // Promisify the callback functions const fileExists = promisify(fs.exists); @@ -105,7 +105,7 @@ const cypressRunner = async function () { configFile, config: { env, - video: true, + video: shouldRecordVideo(), videosFolder: reportsDir, videoCompression: false, videoUploadOnPasses: false, @@ -132,4 +132,4 @@ if (require.main === module) { cypressRunner(); } -exports.cypressRunner = cypressRunner; \ No newline at end of file +exports.cypressRunner = cypressRunner; diff --git a/src/utils.js b/src/utils.js index 45b68ded..49db0552 100644 --- a/src/utils.js +++ b/src/utils.js @@ -7,4 +7,14 @@ function getAbsolutePath (pathToDir) { return path.join(process.cwd(), pathToDir); } -module.exports.getAbsolutePath = getAbsolutePath; \ No newline at end of file +function shouldRecordVideo () { + let isVideoRecording = process.env.SAUCE_CYPRESS_VIDEO_RECORDING; + if (isVideoRecording === undefined) { + return true; + } + let videoOption = String(isVideoRecording).toLowerCase(); + return videoOption === 'true' || videoOption === '1'; +} + +module.exports.getAbsolutePath = getAbsolutePath; +module.exports.shouldRecordVideo = shouldRecordVideo; \ No newline at end of file diff --git a/tests/env-tests/cypress/integration/env.spec.js b/tests/env-tests/cypress/integration/env.spec.js index c5499cfb..64c94ac3 100644 --- a/tests/env-tests/cypress/integration/env.spec.js +++ b/tests/env-tests/cypress/integration/env.spec.js @@ -1,5 +1,7 @@ /// +const { shouldRecordVideo } = require('../../../../src/utils'); + context('Actions', function () { beforeEach(function () { cy.visit('https://example.cypress.io/commands/actions'); @@ -8,4 +10,8 @@ context('Actions', function () { it('should use .env.json', function () { expect(Cypress.env('foo')).to.equal('BAR'); }); + + it('should skip recording cypress video', function () { + expect(shouldRecordVideo()).to.not.equal('true'); + }); }); diff --git a/tests/unit/src/utils.spec.js b/tests/unit/src/utils.spec.js index 4b701fa3..b2b7c05b 100644 --- a/tests/unit/src/utils.spec.js +++ b/tests/unit/src/utils.spec.js @@ -1,4 +1,4 @@ -const { getAbsolutePath } = require('../../../src/utils'); +const { getAbsolutePath, shouldRecordVideo } = require('../../../src/utils'); describe('.getAbsolutePath', function () { it('returns absolute path unmodified', function () { @@ -7,4 +7,35 @@ describe('.getAbsolutePath', function () { it('translates relative path to absolute', function () { expect(getAbsolutePath('path/to/asset/')).toMatch(/\/path\/to\/asset\/$/); }); +}); + +describe('.shouldRecordVideo', function () { + let previousEnv; + beforeEach(function () { + previousEnv = process.env.SAUCE_CYPRESS_VIDEO_RECORDING; + }); + + it('returns true when SAUCE_CYPRESS_VIDEO_RECORDING is undefined', function () { + expect(shouldRecordVideo()).toEqual(true); + }); + it('returns false when SAUCE_CYPRESS_VIDEO_RECORDING is 0', function () { + process.env.SAUCE_CYPRESS_VIDEO_RECORDING = 0; + expect(shouldRecordVideo()).toEqual(false); + }); + it('returns true when SAUCE_CYPRESS_VIDEO_RECORDING is 1', function () { + process.env.SAUCE_CYPRESS_VIDEO_RECORDING = 1; + expect(shouldRecordVideo()).toEqual(true); + }); + it('returns true when SAUCE_CYPRESS_VIDEO_RECORDING is true', function () { + process.env.SAUCE_CYPRESS_VIDEO_RECORDING = true; + expect(shouldRecordVideo()).toEqual(true); + }); + it('returns false when SAUCE_CYPRESS_VIDEO_RECORDING is false', function () { + process.env.SAUCE_CYPRESS_VIDEO_RECORDING = false; + expect(shouldRecordVideo()).toEqual(false); + }); + + afterEach(function () { + process.env.SAUCE_CYPRESS_VIDEO_RECORDING = previousEnv; + }); }); \ No newline at end of file