Skip to content

Commit

Permalink
Fix end-to-end tests post Next.js migration replayio#4346
Browse files Browse the repository at this point in the history
- In order to run either the mock tests or the end-to-end tests, we need
  a dev server running in CI. Previously, we would spawn that manually
  from inside of a script. Now, we start that from inside of the action
  that does the testing. This means that if you want to run the tests
  locally, you'll also need your local dev server running (which was
  already true).
- Add the `test/examples` and `test/scripts` folder to public. This
  means that we will be able to run against preview branches as well.
- Add a GitHub action for setting up Next.js with a cache, so we only
  have to copy one line everywhere, not an entire step. It would be nice
  if we could further refactor out the test stripes, because a lot of
  things are repeated 9 times.
- Remove the `dev-server.js` file. If we're going to use next.js, then
  we should try and keep our config as out-of-the-box as possible, in
  order to allow us to stay up-to-date. The fact that the `test` folder
  has to be available on the development server for the tests to run at
  all seems like the real problem here. A good follow-on task would be
  to sort out the best way to handle those files in the test/dev
  environment.
- Go back to node 14 for lock file. I didn't realize when I changed this
  that we were stuck on such an outdated node version. We should fix
  this ASAP, but until then, let's stick with what was working, just to
  minimize the factors that have gone into resolving all of the failing
  tests.
- Log more from playwright tests. This could be annoying, maybe we
  should tune it, but it's nice to know what's going on in these tests,
  and we're only going to look at the output when something is failing
  anyways, so it may as well be verbose.
- Disable the worst of the failing tests.

That's true! We still have flaky, intermittent tests. The goal of this
PR was to get things to *run*, getting them to pass is a future us
problem! I have been unable to get the mock tests to work to any extent
on CI, although they do pass intermittently locally.

There are also tests (it doesn't seem to be consistent which ones) where
the browser starts up and just never seems to navigate to the page
properly. I haven't been able to figure out where it's getting stuck,
but when tests time out now, it's usually for this reason.

I'm going to put these into a notion doc as well, but documenting here
couldn't hurt. Three things that tripped me up on this PR:

- *any* merge conflicts mean actions *will not run at all*. If you have
  a branch and it's unclear why actions aren't kicking off, make sure
  you check for and resolve merge conflicts.
- When using actions that are type `javascript` your `inputs` get
  automatically turned into environment variables, which is convenient.
  However **when using `composite` actions this won't happen**. You have
  to manually pass the environment variables in with an
  [expression](https://docs.github.com/en/actions/learn-github-actions/expressions).
- The `checkout` action that we use all the time performs a strict
  `clean` of the directory that it's about to clone into! So, if you are
  trying to do some sort of caching or otherwise unloading assets into a
  dir that you also need to do `git checkout XXXX` in (with the checkout
  action), you either need to checkout *first*, or you can use `[clean:
  false](https://github.com/actions/checkout#usage)` I think, though I
  haven't actually tried this.

Fixes replayio#4313
  • Loading branch information
ryanjduffy authored and jcmorrow committed Nov 9, 2021
1 parent d6220a4 commit 2ff10bb
Show file tree
Hide file tree
Showing 133 changed files with 8,729 additions and 6,587 deletions.
17 changes: 13 additions & 4 deletions .github/actions/mockTest/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
name: "Mock Test"
name: "Mock Tests"
description: "Run mock tests"

runs:
using: "node12"
main: "./main.js"
using: "composite"
steps:
- name: Copy .env file
run: cp .env.sample .env
shell: bash
- name: Start Next.js development server
run: ./node_modules/.bin/next dev -p 8080 &
shell: bash
- run: node ${{ github.action_path }}/main.js
shell: bash
env:
DEBUG: "pw:api"
30 changes: 1 addition & 29 deletions .github/actions/mockTest/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,14 @@ const devtools = `${__dirname}/../../..`;

console.log(new Date(), "Start");

spawnCheckedRetry("npm", ["install"], { cwd: devtools, stdio: "inherit" });
const devServerProcess = spawn("node_modules/.bin/webpack", ["serve"], {
cwd: devtools,
stdio: ["inherit", "pipe", "inherit"],
});

console.log(new Date(), "Installed devtools and started webpack build");

(async function () {
console.log("Waiting for Webpack server start");
await Promise.race([
new Promise(r => {
devServerProcess.stdout.on("data", chunk => {
process.stdout.write(chunk);
// Once the dev server starts outputting stuff, we assume it has started
// its server and it is safe to curl.
r();
});
}),
new Promise(r => setTimeout(r, 10 * 1000)).then(() => {
throw new Error("Failed to start dev server");
}),
]);
console.log("Waiting for Webpack build");

// Wait for the initial Webpack build to complete before
// trying to run the tests so the tests don't run
// the risk of timing out if the build itself is slow.
spawnChecked(
"curl",
["--max-time", "600", "--range", "0-50", "http://localhost:8080/dist/main.js"],
["--max-time", "180", "--range", "0-50", "http://localhost:8080/test/harness.js"],
{
stdio: "inherit",
}
);
console.log("Done Initial Webpack build");

spawnChecked("node", [`${devtools}/test/mock/run`], { stdio: "inherit" });
process.exit(0);
Expand Down
13 changes: 13 additions & 0 deletions .github/actions/npm-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "npm install"
description: "Installs dependencies from npm, with caching"
runs:
using: "composite"
steps:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: "14"
cache: "npm"
- name: Install dependencies
run: npm ci
shell: bash
14 changes: 14 additions & 0 deletions .github/actions/setup-next/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Setup Next.js"
description: "Restores the .next/cache folder"
runs:
using: "composite"
steps:
- name: "Setup NextJS Cache"
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
24 changes: 17 additions & 7 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
name: "Test"
description: "Run correctness tests"
description: "Run end-to-end tests. Note that this action assumes that Node and Next.js have already been properly setup. See the setup-next task for details."
inputs:
stripe:
description: "Stripe to run, in the form INDEX/TOTAL"
required: true
github_ci:
description: "A flag to tell whether we are in CI"
required: false

runs:
using: "node12"
main: "./main.js"
using: "composite"
steps:
- run: mv node_modules/node_modules.tgz ./
shell: bash
- run: tar -xzf node_modules.tgz
shell: bash
- name: Copy .env file
run: cp .env.sample .env
shell: bash
- name: Start Next.js development server
run: ./node_modules/.bin/next dev -p 8080 &
shell: bash
- run: node ${{ github.action_path }}/main.js
shell: bash
env:
INPUT_STRIPE: ${{ inputs.stripe }}
51 changes: 9 additions & 42 deletions .github/actions/test/main.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
const fs = require("fs");
const { spawnSync, spawn } = require("child_process");
const { spawnSync } = require("child_process");

function spawnChecked(...args) {
console.log(`spawn`, args);
console.log(`Spawning`, args);
const rv = spawnSync.apply(this, args);
if (rv.status != 0 || rv.error) {
throw new Error("Spawned process failed");
}
console.log(`Spawned`, args);
}

function checkForFile(path) {
console.log(`Checking for file: ${path}`);
if (!fs.existsSync(path)) {
throw new Error(`Required file/directory does not exist: ${path}`);
}
console.log(`Found ${path}`);
}

checkForFile("dist/dist.tgz");
checkForFile("replay/replay.dmg");
checkForFile("replay-node/macOS-replay-node");
checkForFile("replay-driver/macOS-recordreplay.so");

console.log(new Date(), "Start");

spawnChecked("mv", ["dist/dist.tgz", "dist.tgz"]);
spawnChecked("tar", ["-xzf", "dist.tgz"]);

console.log(new Date(), "Unpackaged distribution");

spawnChecked("hdiutil", ["attach", "replay/replay.dmg"]);
spawnChecked("cp", ["-R", "/Volumes/Replay/Replay.app", "/Applications"]);
try {
Expand All @@ -41,39 +36,11 @@ spawnChecked("chmod", ["+x", "replay-node/macOS-replay-node"]);
process.env.RECORD_REPLAY_NODE = "replay-node/macOS-replay-node";
process.env.RECORD_REPLAY_DRIVER = "replay-driver/macOS-recordreplay.so";

const devServerProcess = spawn("node_modules/.bin/webpack", ["serve"], {
detached: true,
stdio: ["inherit", "pipe", "inherit"],
});

(async function () {
console.log("Waiting for Webpack server start");
await Promise.race([
new Promise(r => {
devServerProcess.stdout.on("data", chunk => {
process.stdout.write(chunk);
// Once the dev server starts outputting stuff, we assume it has started
// its server and it is safe to curl.
r();
});
}),
new Promise(r => setTimeout(r, 10 * 1000)).then(() => {
throw new Error("Failed to start dev server");
}),
]);
console.log("Waiting for Webpack build");

// Wait for the initial Webpack build to complete before
// trying to run the tests so the tests don't run
// the risk of timing out if the build itself is slow.
spawnChecked(
"curl",
["--max-time", "600", "--range", "0-50", "http://localhost:8080/dist/main.js"],
{
stdio: "inherit",
}
);
console.log("Done Initial Webpack build");
spawnChecked("curl", ["--max-time", "180", "--range", "0-50", "http://localhost:8080/"], {
stdio: "inherit",
});
console.log("Made contact with server on localhost:8080");

require("../../../test/run");
})().catch(err => {
Expand Down
Loading

0 comments on commit 2ff10bb

Please sign in to comment.