Skip to content

refactor: move integration tests to Jest #5275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jun 24, 2022

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Jun 15, 2022

Description

This PR refactors our integration tests to be written in TypeScript and run with Jest instead of bash. It also adds a helper inspired by the Next.js team to make it easy to test code-server commands.

Motivation

We currently only have one integration test and it's not easy to write new ones because Bash and it's all in one file.

This should make it easier to write integration tests, specifically around the CLI. This is also prep work for #5031

Before

Here is what our integration tests looked like:

#!/usr/bin/env bash
set -euo pipefail

# Make sure a code-server release works. You can pass in the path otherwise it
# will use release-standalone in the current directory.
#
# This is to make sure we don't have Node version errors or any other
# compilation-related errors.
main() {
  cd "$(dirname "${0}")/../.."

  local EXTENSIONS_DIR
  EXTENSIONS_DIR="$(mktemp -d)"

  local path=${1:-./release-standalone/bin/code-server}

  echo "Testing standalone release in $path."

  # NOTE: using a basic theme extension because it doesn't update often and is more reliable for testing
  "$path" --extensions-dir "$EXTENSIONS_DIR" --install-extension wesbos.theme-cobalt2
  local installed_extensions
  installed_extensions="$("$path" --extensions-dir "$EXTENSIONS_DIR" --list-extensions 2>&1)"
  # We use grep as wesbos.theme-cobalt2 may have dependency extensions that change.
  if ! echo "$installed_extensions" | grep -q "wesbos.theme-cobalt2"; then
    echo "Unexpected output from listing extensions:"
    echo "$installed_extensions"
    exit 1
  fi

  echo "Standalone release works correctly."
}

main "$@"

After

This is what they'll look like moving forward:

import { clean, tmpdir } from "../utils/helpers"
import { runCodeServerCommand } from "../utils/integration"

describe("--install-extension", () => {
  const testName = "installExtension"
  let tempDir: string
  let setupFlags: string[]

  beforeEach(async () => {
    await clean(testName)
    tempDir = await tmpdir(testName)
    setupFlags = ["--extensions-dir", tempDir]
  })
  it("should install an extension", async () => {
    const extName = "wesbos.theme-cobalt2"
    await runCodeServerCommand([...setupFlags, "--install-extension", extName], {})
    const { stdout } = await runCodeServerCommand([...setupFlags, "--list-extensions"], {
      stdout: "log",
    })
    expect(stdout).toContain(extName)
  })
})

Fixes N/A

@github-actions
Copy link

github-actions bot commented Jun 15, 2022

✨ code-server docs for PR #5275 is ready! It will be updated on every commit.

@jsjoeio jsjoeio changed the title wip refactor: move integration tests to Jest Jun 15, 2022
@jsjoeio jsjoeio self-assigned this Jun 15, 2022
@jsjoeio jsjoeio added the testing Anything related to testing label Jun 15, 2022
@jsjoeio jsjoeio added this to the June 2022 milestone Jun 15, 2022
@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 18:17 Inactive
@github-actions
Copy link

github-actions bot commented Jun 16, 2022

✨ code-server dev build published to npm for PR #5275!

  • Last publish status: success
  • Commit: 53e82a6

To install in a local project, run:

npm install @coder/code-server-pr@5275

To install globally, run:

npm install -g @coder/code-server-pr@5275

@codecov
Copy link

codecov bot commented Jun 16, 2022

Codecov Report

Merging #5275 (2d892d4) into main (a879844) will not change coverage.
The diff coverage is n/a.

❗ Current head 2d892d4 differs from pull request most recent head 53e82a6. Consider uploading reports for the commit 53e82a6 to get more accurate results

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #5275   +/-   ##
=======================================
  Coverage   72.47%   72.47%           
=======================================
  Files          30       30           
  Lines        1671     1671           
  Branches      367      367           
=======================================
  Hits         1211     1211           
  Misses        397      397           
  Partials       63       63           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a879844...53e82a6. Read the comment docs.

@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 19:05 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 19:32 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 20:35 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 20:57 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 21:13 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 21:23 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 21:49 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 22:52 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 16, 2022 23:03 Inactive
@jsjoeio
Copy link
Contributor Author

jsjoeio commented Jun 17, 2022

possible workaround is to manually checkout submodules
actions/checkout#758 (comment)

@jsjoeio jsjoeio temporarily deployed to npm June 17, 2022 15:35 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 17, 2022 15:57 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 17, 2022 16:13 Inactive
@jsjoeio jsjoeio force-pushed the jsjoeio/refactor-integration-tests branch from e25edab to 8bb7cfe Compare June 17, 2022 18:24
Comment on lines 291 to 295
- name: Install test dependencies
run: yarn install --ignore-scripts && cd test && yarn install

- name: Run integration tests on standalone release
run: yarn test:integration
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: I had to use --ignore-scripts because otherwise yarn install fails if you don't checkout the repo with submodules. On the Linux job that runs on CentOS7, it didn't have the latest git so this one-liner was the best alternative. It ensures we have the right TS/Jest dependencies to run the yarn test:integration step.

@@ -34,7 +34,7 @@ jobs:
run: ./install.sh

- name: Test code-server
run: yarn test:standalone-release code-server
run: CODE_SERVER_PATH="code-server" yarn test:integration
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we install code-server in these steps, we need to tell the integration tests to look at code-server and use the CLI/binary.

@jsjoeio jsjoeio marked this pull request as ready for review June 17, 2022 18:36
@jsjoeio jsjoeio requested a review from a team June 17, 2022 18:36
@jsjoeio jsjoeio temporarily deployed to npm June 17, 2022 18:38 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 17, 2022 20:35 Inactive
@jsjoeio jsjoeio force-pushed the jsjoeio/refactor-integration-tests branch from fe376a1 to 0539413 Compare June 17, 2022 20:48
@jsjoeio jsjoeio temporarily deployed to npm June 17, 2022 20:52 Inactive
@jsjoeio jsjoeio temporarily deployed to npm June 17, 2022 22:30 Inactive
@jsjoeio jsjoeio force-pushed the jsjoeio/refactor-integration-tests branch from 844bcca to f76acab Compare June 23, 2022 16:19
@jsjoeio jsjoeio temporarily deployed to npm June 23, 2022 16:24 Inactive
Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

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

Happy to see this move into our standard testing framework!

@jsjoeio jsjoeio temporarily deployed to npm June 23, 2022 19:17 Inactive
@jsjoeio jsjoeio requested a review from code-asher June 23, 2022 19:20
*/
export async function runCodeServerCommand(argv: string[]): Promise<{ stdout: string; stderr: string }> {
const CODE_SERVER_COMMAND = process.env.CODE_SERVER_PATH || "/var/tmp/coder/code-server/bin/code-server"
const { stdout, stderr } = await promisify(exec)(`${CODE_SERVER_COMMAND} ${argv.join(" ")}`)

Check warning

Code scanning / CodeQL

Shell command built from environment values

This shell command depends on an uncontrolled [absolute path](1). This shell command depends on an uncontrolled [absolute path](2).
@jsjoeio jsjoeio temporarily deployed to npm June 23, 2022 19:24 Inactive
@jsjoeio jsjoeio enabled auto-merge (squash) June 23, 2022 20:41
@jsjoeio jsjoeio temporarily deployed to npm June 24, 2022 16:30 Inactive
@jsjoeio jsjoeio merged commit c51ff3b into main Jun 24, 2022
@jsjoeio jsjoeio deleted the jsjoeio/refactor-integration-tests branch June 24, 2022 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Anything related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants