From 8482cbe22d1a421b73db602e1f470c632b09f693 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sun, 2 Dec 2018 11:25:45 -0800 Subject: [PATCH] Automated fixture tests (#14370) * Renamed snapshot test from test.js to snapshot-test.js * Automate fixtures tests --- fixtures/tracing/index.html | 13 +- scripts/release/package.json | 2 + .../prepare-canary-commands/parse-params.js | 6 + scripts/release/prepare-canary.js | 8 + .../prepare-stable-commands/parse-params.js | 6 + .../update-stable-version-numbers.js | 2 + scripts/release/prepare-stable.js | 8 + .../print-prerelease-summary.js | 9 +- .../shared-commands/test-packaging-fixture.js | 74 +++ .../shared-commands/test-scheduler-fixture.js | 54 ++ scripts/release/{test.js => snapshot-test.js} | 16 +- .../{test.snapshot => snapshot-test.snapshot} | 0 scripts/release/yarn.lock | 514 +++++++++++++++++- 13 files changed, 695 insertions(+), 17 deletions(-) create mode 100644 scripts/release/shared-commands/test-packaging-fixture.js create mode 100644 scripts/release/shared-commands/test-scheduler-fixture.js rename scripts/release/{test.js => snapshot-test.js} (85%) rename scripts/release/{test.snapshot => snapshot-test.snapshot} (100%) diff --git a/fixtures/tracing/index.html b/fixtures/tracing/index.html index 07d9b2a8cc..deb285110d 100644 --- a/fixtures/tracing/index.html +++ b/fixtures/tracing/index.html @@ -46,7 +46,7 @@

Tests - +

  1. @@ -62,6 +62,17 @@ Test end-to-end integration
+ + + diff --git a/scripts/release/package.json b/scripts/release/package.json index e74b01ce9f..9aa39a4ae4 100644 --- a/scripts/release/package.json +++ b/scripts/release/package.json @@ -17,6 +17,8 @@ "log-update": "^2.1.0", "progress-estimator": "^0.2.1", "prompt-promise": "^1.0.3", + "puppeteer": "^1.11.0", + "pushstate-server": "^3.0.1", "request-promise-json": "^1.0.4", "semver": "^5.4.1" } diff --git a/scripts/release/prepare-canary-commands/parse-params.js b/scripts/release/prepare-canary-commands/parse-params.js index acc87b8aac..703fc0fb11 100644 --- a/scripts/release/prepare-canary-commands/parse-params.js +++ b/scripts/release/prepare-canary-commands/parse-params.js @@ -11,6 +11,12 @@ const paramDefinitions = [ description: 'Circle CI build identifier (e.g. https://circleci.com/gh/facebook/react/)', }, + { + name: 'skipTests', + type: Boolean, + description: 'Skip automated fixture tests.', + defaultValue: false, + }, ]; module.exports = () => { diff --git a/scripts/release/prepare-canary.js b/scripts/release/prepare-canary.js index d2524405a6..7133b5d763 100755 --- a/scripts/release/prepare-canary.js +++ b/scripts/release/prepare-canary.js @@ -10,6 +10,8 @@ const downloadBuildArtifacts = require('./prepare-canary-commands/download-build const getLatestMasterBuildNumber = require('./prepare-canary-commands/get-latest-master-build-number'); const parseParams = require('./prepare-canary-commands/parse-params'); const printPrereleaseSummary = require('./shared-commands/print-prerelease-summary'); +const testPackagingFixture = require('./shared-commands/test-packaging-fixture'); +const testSchedulerFixture = require('./shared-commands/test-scheduler-fixture'); const run = async () => { try { @@ -23,6 +25,12 @@ const run = async () => { await checkEnvironmentVariables(params); await downloadBuildArtifacts(params); + + if (!params.skipTests) { + await testPackagingFixture(params); + await testSchedulerFixture(params); + } + await printPrereleaseSummary(params); } catch (error) { handleError(error); diff --git a/scripts/release/prepare-stable-commands/parse-params.js b/scripts/release/prepare-stable-commands/parse-params.js index ef8c941105..4046d130cb 100644 --- a/scripts/release/prepare-stable-commands/parse-params.js +++ b/scripts/release/prepare-stable-commands/parse-params.js @@ -13,6 +13,12 @@ const paramDefinitions = [ 'Skip NPM and use the build already present in "build/node_modules".', defaultValue: false, }, + { + name: 'skipTests', + type: Boolean, + description: 'Skip automated fixture tests.', + defaultValue: false, + }, { name: 'version', type: String, diff --git a/scripts/release/prepare-stable-commands/update-stable-version-numbers.js b/scripts/release/prepare-stable-commands/update-stable-version-numbers.js index cdd7ee03ea..a655755283 100644 --- a/scripts/release/prepare-stable-commands/update-stable-version-numbers.js +++ b/scripts/release/prepare-stable-commands/update-stable-version-numbers.js @@ -170,6 +170,8 @@ const run = async ({cwd, packages, version}, versionsMap) => { theme`A full diff is available at {path ${relative(cwd, diffPath)}}.` ); await confirm('Do the changes above look correct?'); + + clear(); }; // Run this directly because logPromise would interfere with printing package dependencies. diff --git a/scripts/release/prepare-stable.js b/scripts/release/prepare-stable.js index 733cb109e9..a651747cd6 100755 --- a/scripts/release/prepare-stable.js +++ b/scripts/release/prepare-stable.js @@ -10,6 +10,8 @@ const confirmStableVersionNumbers = require('./prepare-stable-commands/confirm-s const guessStableVersionNumbers = require('./prepare-stable-commands/guess-stable-version-numbers'); const parseParams = require('./prepare-stable-commands/parse-params'); const printPrereleaseSummary = require('./shared-commands/print-prerelease-summary'); +const testPackagingFixture = require('./shared-commands/test-packaging-fixture'); +const testSchedulerFixture = require('./shared-commands/test-scheduler-fixture'); const updateStableVersionNumbers = require('./prepare-stable-commands/update-stable-version-numbers'); const run = async () => { @@ -27,6 +29,12 @@ const run = async () => { await guessStableVersionNumbers(params, versionsMap); await confirmStableVersionNumbers(params, versionsMap); await updateStableVersionNumbers(params, versionsMap); + + if (!params.skipTests) { + await testPackagingFixture(params); + await testSchedulerFixture(params); + } + await printPrereleaseSummary(params); } catch (error) { handleError(error); diff --git a/scripts/release/shared-commands/print-prerelease-summary.js b/scripts/release/shared-commands/print-prerelease-summary.js index e68d014745..d981bd28fe 100644 --- a/scripts/release/shared-commands/print-prerelease-summary.js +++ b/scripts/release/shared-commands/print-prerelease-summary.js @@ -22,14 +22,7 @@ module.exports = ({cwd}) => { {header Before publishing, please smoke test the packages!} - 1. Open {path ./fixtures/packaging/babel-standalone/dev.html} in the browser. - 2. It should say {quote "Hello world!"} - 3. Next go to {path ./fixtures/packaging} and run {command node build-all.js} - 4. Go to the repo root and {command npx pushstate-server . 9000} - 5. Open {link http://localhost:9000/fixtures/packaging} - 6. Verify every iframe shows {quote "Hello world!"} - - After completing the above steps, you can publish this release by running: + Once you have finished smoke testing, you can publish this release by running: {path ${publishPath}} ` .replace(/\n +/g, '\n') diff --git a/scripts/release/shared-commands/test-packaging-fixture.js b/scripts/release/shared-commands/test-packaging-fixture.js new file mode 100644 index 0000000000..5bfc5cd9c6 --- /dev/null +++ b/scripts/release/shared-commands/test-packaging-fixture.js @@ -0,0 +1,74 @@ +#!/usr/bin/env node + +'use strict'; + +const {exec} = require('child-process-promise'); +const {join} = require('path'); +const puppeteer = require('puppeteer'); +const server = require('pushstate-server'); +const theme = require('../theme'); +const {logPromise} = require('../utils'); + +const validate = async () => { + const browser = await puppeteer.launch(); + const page = await browser.newPage(); + + await page.goto('http://localhost:9000/fixtures/packaging'); + + try { + return await page.evaluate(() => { + const iframes = document.querySelectorAll('iframe'); + + if (iframes.length === 0) { + return 'No iframes were found.'; + } + + for (let i = 0; i < iframes.length; i++) { + const iframe = iframes[i]; + // Don't include the