From fb2533ce60295134ac48edd5cae389d062942ebe Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 20 Dec 2022 15:59:05 -0700 Subject: [PATCH 01/13] wip: migrate vscode tests to e2e --- test/e2e/routes.test.ts | 72 ++++++++++++++++++++++++++++ test/unit/node/routes/vscode.test.ts | 23 +-------- 2 files changed, 73 insertions(+), 22 deletions(-) create mode 100644 test/e2e/routes.test.ts diff --git a/test/e2e/routes.test.ts b/test/e2e/routes.test.ts new file mode 100644 index 000000000000..94d9bc21d8f6 --- /dev/null +++ b/test/e2e/routes.test.ts @@ -0,0 +1,72 @@ +import { describe, test, expect } from "./baseFixture" +import { clean, tmpdir } from "../utils/helpers" +import * as path from "path" +import { promises as fs } from "fs" + +describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => { + const testName = "integrated-terminal" + test.beforeAll(async () => { + await clean(testName) + }) + const routes = ["/", "/vscode", "/vscode/"] + + test("should load all route variations", async ({ codeServerPage }) => { + for (const route of routes) { + await codeServerPage.navigate(route) + + // Check there were no redirections + const url = new URL(codeServerPage.page.url()) + expect(url.pathname).toBe(route) + + // Check that page loaded from correct route + const html = await codeServerPage.page.innerHTML("html") + switch (route) { + case "/": + case "/vscode/": + expect(html).toMatch(/src="\.\/[a-z]+-[0-9a-z]+\/static\//) + break + case "/vscode": + expect(html).toMatch(/src="\.\/vscode\/[a-z]+-[0-9a-z]+\/static\//) + break + } + } + }) + + test("should redirect to the passed in workspace using human-readable query", async ({ codeServerPage }) => { + const workspace = path.join(await tmpdir(testName), "test.code-workspace") + await fs.writeFile(workspace, "") + + const url = new URL(codeServerPage.page.url()) + expect(url.pathname).toBe("/") + expect(url.search).toBe(`?workspace=${workspace}`) + }) +}) + +const CODE_WORKSPACE_DIR = process.env.CODE_WORKSPACE_DIR || "" +describe("VS Code Routes with code-workspace", ["--disable-workspace-trust", CODE_WORKSPACE_DIR], {}, async () => { + const testName = "vscode-routes" + test.beforeAll(async () => { + await clean(testName) + }) + + test("should redirect to the passed in workspace using human-readable query", async ({ codeServerPage }) => { + const url = new URL(codeServerPage.page.url()) + expect(url.pathname).toBe("/") + expect(url.search).toBe(`?workspace=${CODE_WORKSPACE_DIR}`) + }) +}) + +describe( + "VS Code Routes with ignore-last-opened", + ["--disable-workspace-trust", "--ignore-last-opened"], + {}, + async () => { + test("should not redirect", async ({ codeServerPage }) => { + await codeServerPage.navigate(`/`) + // No redirections. + const url = new URL(codeServerPage.page.url()) + expect(url.pathname).toBe("/") + expect(url.search).toBe("") + }) + }, +) diff --git a/test/unit/node/routes/vscode.test.ts b/test/unit/node/routes/vscode.test.ts index 5d3dbb63d944..356423f44333 100644 --- a/test/unit/node/routes/vscode.test.ts +++ b/test/unit/node/routes/vscode.test.ts @@ -32,6 +32,7 @@ describe.skip("vscode", () => { const html = await resp.text() const url = new URL(resp.url) // Check there were no redirections. expect(url.pathname + url.search).toBe(route) + switch (route) { case "/": case "/vscode/": @@ -112,26 +113,4 @@ describe.skip("vscode", () => { expect(url.search).toBe("") await resp.text() }) - - it("should not redirect when last opened is ignored", async () => { - codeServer = await integration.setup(["--auth=none", "--ignore-last-opened"], "") - - const folder = await tmpdir(testName) - const workspace = path.join(await tmpdir(testName), "test.code-workspace") - await fs.writeFile(workspace, "") - - let resp = await codeServer.fetch("/", undefined, { - folder, - workspace, - }) - expect(resp.status).toBe(200) - await resp.text() - - // No redirections. - resp = await codeServer.fetch("/") - const url = new URL(resp.url) - expect(url.pathname).toBe("/") - expect(url.search).toBe("") - await resp.text() - }) }) From 6c8db6c9957d23bacc901978d220f33a430fa8be Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 20 Dec 2022 15:59:33 -0700 Subject: [PATCH 02/13] feat: add codeWorkspace to global setup --- test/utils/globalE2eSetup.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/utils/globalE2eSetup.ts b/test/utils/globalE2eSetup.ts index 3596ed33f34e..53ff92382eef 100644 --- a/test/utils/globalE2eSetup.ts +++ b/test/utils/globalE2eSetup.ts @@ -1,6 +1,8 @@ import { workspaceDir } from "./constants" -import { clean } from "./helpers" +import { clean, tmpdir } from "./helpers" import * as wtfnode from "./wtfnode" +import * as path from "path" +import { promises as fs } from "fs" /** * Perform workspace cleanup and authenticate. This should be ran before e2e @@ -17,5 +19,10 @@ export default async function () { wtfnode.setup() } + // Create dummy code-workspace + const codeWorkspace = path.join(await tmpdir(workspaceDir), "test.code-workspace") + await fs.writeFile(codeWorkspace, "") + process.env.CODE_WORKSPACE_DIR = codeWorkspace + console.log("✅ Global Setup for Playwright End-to-End Tests is now complete.") } From c7199fd7df226c469b7635efa6275e93946a5f46 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 20 Dec 2022 16:03:16 -0700 Subject: [PATCH 03/13] refactor: only use dir in spawn when we should --- test/e2e/models/CodeServer.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index f2c2e0cc431d..0f286071c2d0 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -119,7 +119,7 @@ export class CodeServer { private async spawn(): Promise { // This will be used both as the workspace and data directory to ensure // instances don't bleed into each other. - const dir = await this.createWorkspace() + let dir = await this.createWorkspace() return new Promise((resolve, reject) => { const args = [ @@ -128,6 +128,8 @@ export class CodeServer { path.join(dir, "extensions"), "--auth", "none", + // The last argument is the workspace to open. + ...(this.args.includes("--ignore-last-opened") ? [] : [dir]), ...this.args, // Using port zero will spawn on a random port. "--bind-addr", @@ -139,8 +141,6 @@ export class CodeServer { path.join(dir, "config.yaml"), "--user-data-dir", dir, - // The last argument is the workspace to open. - dir, ] this.logger.debug("spawning `node " + args.join(" ") + "`") const proc = cp.spawn("node", args, { From 42b873fbfc3c42c60e753a19371593a5290129d3 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 09:26:34 -0700 Subject: [PATCH 04/13] wip: migrate more tests --- test/e2e/routes.test.ts | 14 +++++++++ test/unit/node/routes/vscode.test.ts | 43 ---------------------------- test/utils/globalE2eSetup.ts | 6 +++- 3 files changed, 19 insertions(+), 44 deletions(-) diff --git a/test/e2e/routes.test.ts b/test/e2e/routes.test.ts index 94d9bc21d8f6..bce1907fcc62 100644 --- a/test/e2e/routes.test.ts +++ b/test/e2e/routes.test.ts @@ -56,6 +56,20 @@ describe("VS Code Routes with code-workspace", ["--disable-workspace-trust", COD }) }) +const CODE_FOLDER_DIR = process.env.CODE_FOLDER_DIR || "" +describe("VS Code Routes with code-workspace", ["--disable-workspace-trust", CODE_FOLDER_DIR], {}, async () => { + const testName = "vscode-routes" + test.beforeAll(async () => { + await clean(testName) + }) + + test.only("should redirect to the passed in folder using human-readable query", async ({ codeServerPage }) => { + const url = new URL(codeServerPage.page.url()) + expect(url.pathname).toBe("/") + expect(url.search).toBe(`?folder=${CODE_FOLDER_DIR}`) + }) +}) + describe( "VS Code Routes with ignore-last-opened", ["--disable-workspace-trust", "--ignore-last-opened"], diff --git a/test/unit/node/routes/vscode.test.ts b/test/unit/node/routes/vscode.test.ts index 356423f44333..813f1a9f5e1f 100644 --- a/test/unit/node/routes/vscode.test.ts +++ b/test/unit/node/routes/vscode.test.ts @@ -23,49 +23,6 @@ describe.skip("vscode", () => { const routes = ["/", "/vscode", "/vscode/"] - it("should load all route variations", async () => { - codeServer = await integration.setup(["--auth=none"], "") - - for (const route of routes) { - const resp = await codeServer.fetch(route) - expect(resp.status).toBe(200) - const html = await resp.text() - const url = new URL(resp.url) // Check there were no redirections. - expect(url.pathname + url.search).toBe(route) - - switch (route) { - case "/": - case "/vscode/": - expect(html).toMatch(/src="\.\/[a-z]+-[0-9a-z]+\/static\//) - break - case "/vscode": - expect(html).toMatch(/src="\.\/vscode\/[a-z]+-[0-9a-z]+\/static\//) - break - } - } - }) - - it("should redirect to the passed in workspace using human-readable query", async () => { - const workspace = path.join(await tmpdir(testName), "test.code-workspace") - await fs.writeFile(workspace, "") - codeServer = await integration.setup(["--auth=none", workspace], "") - - const resp = await codeServer.fetch("/") - const url = new URL(resp.url) - expect(url.pathname).toBe("/") - expect(url.search).toBe(`?workspace=${workspace}`) - }) - - it("should redirect to the passed in folder using human-readable query", async () => { - const folder = await tmpdir(testName) - codeServer = await integration.setup(["--auth=none", folder], "") - - const resp = await codeServer.fetch("/") - const url = new URL(resp.url) - expect(url.pathname).toBe("/") - expect(url.search).toBe(`?folder=${folder}`) - }) - it("should redirect to last query folder/workspace", async () => { codeServer = await integration.setup(["--auth=none"], "") diff --git a/test/utils/globalE2eSetup.ts b/test/utils/globalE2eSetup.ts index 53ff92382eef..107dc85fa0d7 100644 --- a/test/utils/globalE2eSetup.ts +++ b/test/utils/globalE2eSetup.ts @@ -19,10 +19,14 @@ export default async function () { wtfnode.setup() } - // Create dummy code-workspace + // Create dummy code-workspace for routes.test.ts const codeWorkspace = path.join(await tmpdir(workspaceDir), "test.code-workspace") await fs.writeFile(codeWorkspace, "") process.env.CODE_WORKSPACE_DIR = codeWorkspace + // Create dummy folder for routes.test.ts + const folder = await tmpdir(workspaceDir) + process.env.CODE_FOLDER_DIR = folder + console.log("✅ Global Setup for Playwright End-to-End Tests is now complete.") } From 033728ad1a29e0c58cb0d74e7c7876ccd60ff8c9 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 09:42:47 -0700 Subject: [PATCH 05/13] refactor: move all vscode tests to e2e --- test/e2e/routes.test.ts | 46 +++++++++++++++++- test/unit/node/routes/vscode.test.ts | 73 ---------------------------- 2 files changed, 44 insertions(+), 75 deletions(-) delete mode 100644 test/unit/node/routes/vscode.test.ts diff --git a/test/e2e/routes.test.ts b/test/e2e/routes.test.ts index bce1907fcc62..690a12fe2ac0 100644 --- a/test/e2e/routes.test.ts +++ b/test/e2e/routes.test.ts @@ -3,12 +3,13 @@ import { clean, tmpdir } from "../utils/helpers" import * as path from "path" import { promises as fs } from "fs" +const routes = ["/", "/vscode", "/vscode/"] + describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => { const testName = "integrated-terminal" test.beforeAll(async () => { await clean(testName) }) - const routes = ["/", "/vscode", "/vscode/"] test("should load all route variations", async ({ codeServerPage }) => { for (const route of routes) { @@ -63,7 +64,7 @@ describe("VS Code Routes with code-workspace", ["--disable-workspace-trust", COD await clean(testName) }) - test.only("should redirect to the passed in folder using human-readable query", async ({ codeServerPage }) => { + test("should redirect to the passed in folder using human-readable query", async ({ codeServerPage }) => { const url = new URL(codeServerPage.page.url()) expect(url.pathname).toBe("/") expect(url.search).toBe(`?folder=${CODE_FOLDER_DIR}`) @@ -84,3 +85,44 @@ describe( }) }, ) + +describe( + "VS Code Routes with no workspace or folder", + ["--disable-workspace-trust"], + {}, + async () => { + test("should redirect to last query folder/workspace", async ({ codeServerPage }) => { + const folder = process.env.CODE_FOLDER_DIR + const workspace = process.env.CODE_WORKSPACE_DIR + await codeServerPage.navigate(`/?folder=${folder}&workspace=${workspace}`) + + // If you visit again without query parameters it will re-attach them by + // redirecting. It should always redirect to the same route. + for (const route of routes) { + await codeServerPage.navigate(route) + const url = new URL(codeServerPage.page.url()) + expect(url.pathname).toBe(route) + expect(url.search).toBe(`?folder=${folder}&workspace=${workspace}`) + } + }) + }, +) + +describe( + "VS Code Routes with no workspace or folder", + ["--disable-workspace-trust"], + {}, + async () => { + test("should not redirect if ew passed in", async ({ codeServerPage }) => { + const folder = process.env.CODE_FOLDER_DIR + const workspace = process.env.CODE_WORKSPACE_DIR + await codeServerPage.navigate(`/?folder=${folder}&workspace=${workspace}`) + + // Closing the folder should stop the redirecting. + await codeServerPage.navigate("/?ew=true") + let url = new URL(codeServerPage.page.url()) + expect(url.pathname).toBe("/") + expect(url.search).toBe("?ew=true") + }) + }, +) \ No newline at end of file diff --git a/test/unit/node/routes/vscode.test.ts b/test/unit/node/routes/vscode.test.ts deleted file mode 100644 index 813f1a9f5e1f..000000000000 --- a/test/unit/node/routes/vscode.test.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { promises as fs } from "fs" -import * as path from "path" -import { clean, tmpdir } from "../../../utils/helpers" -import * as httpserver from "../../../utils/httpserver" -import * as integration from "../../../utils/integration" - -// TODO@jsjoeio - move these to integration tests since they rely on Code -// to be built -describe.skip("vscode", () => { - let codeServer: httpserver.HttpServer | undefined - - const testName = "vscode" - beforeAll(async () => { - await clean(testName) - }) - - afterEach(async () => { - if (codeServer) { - await codeServer.dispose() - codeServer = undefined - } - }) - - const routes = ["/", "/vscode", "/vscode/"] - - it("should redirect to last query folder/workspace", async () => { - codeServer = await integration.setup(["--auth=none"], "") - - const folder = await tmpdir(testName) - const workspace = path.join(await tmpdir(testName), "test.code-workspace") - await fs.writeFile(workspace, "") - let resp = await codeServer.fetch("/", undefined, { - folder, - workspace, - }) - expect(resp.status).toBe(200) - await resp.text() - - // If you visit again without query parameters it will re-attach them by - // redirecting. It should always redirect to the same route. - for (const route of routes) { - resp = await codeServer.fetch(route) - const url = new URL(resp.url) - expect(url.pathname).toBe(route) - expect(url.search).toBe(`?folder=${folder}&workspace=${workspace}`) - await resp.text() - } - - // Closing the folder should stop the redirecting. - resp = await codeServer.fetch("/", undefined, { ew: "true" }) - let url = new URL(resp.url) - expect(url.pathname).toBe("/") - expect(url.search).toBe("?ew=true") - await resp.text() - - resp = await codeServer.fetch("/") - url = new URL(resp.url) - expect(url.pathname).toBe("/") - expect(url.search).toBe("") - await resp.text() - }) - - it("should do nothing when nothing is passed in", async () => { - codeServer = await integration.setup(["--auth=none"], "") - - const resp = await codeServer.fetch("/", undefined) - - expect(resp.status).toBe(200) - const url = new URL(resp.url) - expect(url.search).toBe("") - await resp.text() - }) -}) From 99b6e05e935b5e46bdd057a1bdb08c6dd963f740 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 09:45:13 -0700 Subject: [PATCH 06/13] refactor(ci): move unit to own job --- .github/workflows/build.yaml | 56 +++++++++++++++++++++++++++--------- ci/dev/test-unit.sh | 16 ----------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2eacba567b3b..1650f58822b1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -139,6 +139,49 @@ jobs: if: steps.changed-files.outputs.any_changed == 'true' run: yarn lint:ts + test-unit: + name: Run unit tests + runs-on: ubuntu-20.04 + timeout-minutes: 5 + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v26.1 + with: + files: | + **/*.ts + files_ignore: | + lib/vscode/** + + - name: Install Node.js v16 + if: steps.changed-files.outputs.any_changed == 'true' + uses: actions/setup-node@v3 + with: + node-version: "16" + + - name: Fetch dependencies from cache + if: steps.changed-files.outputs.any_changed == 'true' + id: cache-node-modules + uses: actions/cache@v3 + with: + path: "**/node_modules" + key: yarn-build-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + yarn-build- + + - name: Install dependencies + if: steps.changed-files.outputs.any_changed == 'true' && steps.cache-node-modules.outputs.cache-hit != 'true' + run: SKIP_SUBMODULE_DEPS=1 yarn --frozen-lockfile + + - name: Run unit tests + if: steps.changed-files.outputs.any_changed == 'true' + run: yarn test:unit + build: name: Build code-server runs-on: ubuntu-20.04 @@ -206,19 +249,6 @@ jobs: if: steps.cache-vscode.outputs.cache-hit != 'true' run: yarn build:vscode - # Our code imports code from VS Code's `out` directory meaning VS Code - # must be built before running these tests. - # TODO: Move to its own step? - - name: Run code-server unit tests - run: yarn test:unit - if: success() - - - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: success() - # The release package does not contain any native modules # and is neutral to architecture/os/libc version. - name: Create release package diff --git a/ci/dev/test-unit.sh b/ci/dev/test-unit.sh index b3e0b14c908c..e312c073e4ef 100755 --- a/ci/dev/test-unit.sh +++ b/ci/dev/test-unit.sh @@ -11,22 +11,6 @@ main() { make -s out/index.js popd - # Our code imports from `out` in order to work during development but if you - # have only built for production you will have not have this directory. In - # that case symlink `out` to a production build directory. - if [[ ! -e lib/vscode/out ]]; then - pushd lib - local out=(vscode-reh-web-*) - if [[ -d "${out[0]}" ]]; then - ln -s "../${out[0]}/out" ./vscode/out - else - echo "Could not find lib/vscode/out or lib/vscode-reh-web-*" - echo "Code must be built before running unit tests" - exit 1 - fi - popd - fi - # We must keep jest in a sub-directory. See ../../test/package.json for more # information. We must also run it from the root otherwise coverage will not # include our source files. From 466a04a66b6ece95499e15e570f725f61f0cd035 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 09:47:31 -0700 Subject: [PATCH 07/13] fixup: add codecov to unit test step --- .github/workflows/build.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1650f58822b1..101b7577f6cb 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -182,6 +182,12 @@ jobs: if: steps.changed-files.outputs.any_changed == 'true' run: yarn test:unit + - name: Upload coverage report to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + if: success() + build: name: Build code-server runs-on: ubuntu-20.04 From c32e4278005e62538e95c7fa9f8ec88f7c1400cb Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 11:17:21 -0700 Subject: [PATCH 08/13] Update test/e2e/models/CodeServer.ts --- test/e2e/models/CodeServer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index 0f286071c2d0..b4990689c832 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -119,7 +119,7 @@ export class CodeServer { private async spawn(): Promise { // This will be used both as the workspace and data directory to ensure // instances don't bleed into each other. - let dir = await this.createWorkspace() + const dir = await this.createWorkspace() return new Promise((resolve, reject) => { const args = [ From f3bc47bdf9a6600b32a1c45bd225114d60ad620d Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 11:17:49 -0700 Subject: [PATCH 09/13] Update test/e2e/models/CodeServer.ts --- test/e2e/models/CodeServer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index b4990689c832..2fb625627451 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -128,7 +128,7 @@ export class CodeServer { path.join(dir, "extensions"), "--auth", "none", - // The last argument is the workspace to open. + // The workspace to open. ...(this.args.includes("--ignore-last-opened") ? [] : [dir]), ...this.args, // Using port zero will spawn on a random port. From 6f7fefeb1f58ffcbba04b4431e62a900b0ca560d Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 11:19:21 -0700 Subject: [PATCH 10/13] docs: add note about intercept requests --- test/e2e/routes.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/e2e/routes.test.ts b/test/e2e/routes.test.ts index 690a12fe2ac0..542ca0f30940 100644 --- a/test/e2e/routes.test.ts +++ b/test/e2e/routes.test.ts @@ -19,6 +19,11 @@ describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => { const url = new URL(codeServerPage.page.url()) expect(url.pathname).toBe(route) + // TODO@jsjoeio + // now that we are in a proper browser instead of scraping the HTML we + // could possibly intercept requests to make sure assets are loading from + // the right spot. + // // Check that page loaded from correct route const html = await codeServerPage.page.innerHTML("html") switch (route) { From 116ae64bf61ddfa601ab0c6a47d33f82e8290933 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 11:23:39 -0700 Subject: [PATCH 11/13] refactor: rm unused clean() calls --- test/e2e/routes.test.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/test/e2e/routes.test.ts b/test/e2e/routes.test.ts index 542ca0f30940..bf32f7fca403 100644 --- a/test/e2e/routes.test.ts +++ b/test/e2e/routes.test.ts @@ -6,7 +6,7 @@ import { promises as fs } from "fs" const routes = ["/", "/vscode", "/vscode/"] describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => { - const testName = "integrated-terminal" + const testName = "vscode-routes-default" test.beforeAll(async () => { await clean(testName) }) @@ -50,11 +50,6 @@ describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => { const CODE_WORKSPACE_DIR = process.env.CODE_WORKSPACE_DIR || "" describe("VS Code Routes with code-workspace", ["--disable-workspace-trust", CODE_WORKSPACE_DIR], {}, async () => { - const testName = "vscode-routes" - test.beforeAll(async () => { - await clean(testName) - }) - test("should redirect to the passed in workspace using human-readable query", async ({ codeServerPage }) => { const url = new URL(codeServerPage.page.url()) expect(url.pathname).toBe("/") @@ -64,11 +59,6 @@ describe("VS Code Routes with code-workspace", ["--disable-workspace-trust", COD const CODE_FOLDER_DIR = process.env.CODE_FOLDER_DIR || "" describe("VS Code Routes with code-workspace", ["--disable-workspace-trust", CODE_FOLDER_DIR], {}, async () => { - const testName = "vscode-routes" - test.beforeAll(async () => { - await clean(testName) - }) - test("should redirect to the passed in folder using human-readable query", async ({ codeServerPage }) => { const url = new URL(codeServerPage.page.url()) expect(url.pathname).toBe("/") From 5295c27e50b6880f9c3343cd7858617bf196802a Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 11:25:13 -0700 Subject: [PATCH 12/13] refactor: delete duplicate test --- test/e2e/routes.test.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/e2e/routes.test.ts b/test/e2e/routes.test.ts index bf32f7fca403..a202813af6a7 100644 --- a/test/e2e/routes.test.ts +++ b/test/e2e/routes.test.ts @@ -37,15 +37,6 @@ describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => { } } }) - - test("should redirect to the passed in workspace using human-readable query", async ({ codeServerPage }) => { - const workspace = path.join(await tmpdir(testName), "test.code-workspace") - await fs.writeFile(workspace, "") - - const url = new URL(codeServerPage.page.url()) - expect(url.pathname).toBe("/") - expect(url.search).toBe(`?workspace=${workspace}`) - }) }) const CODE_WORKSPACE_DIR = process.env.CODE_WORKSPACE_DIR || "" From f5f89c59a4d2f1761a3c569984d1a385f55597ae Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 21 Dec 2022 11:28:27 -0700 Subject: [PATCH 13/13] refactor: update 'should not redirect' test --- test/e2e/routes.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/e2e/routes.test.ts b/test/e2e/routes.test.ts index a202813af6a7..70e2632ba622 100644 --- a/test/e2e/routes.test.ts +++ b/test/e2e/routes.test.ts @@ -63,8 +63,12 @@ describe( {}, async () => { test("should not redirect", async ({ codeServerPage }) => { + const folder = process.env.CODE_FOLDER_DIR + await codeServerPage.navigate(`/`) - // No redirections. + await codeServerPage.navigate(`/?folder=${folder}`) + await codeServerPage.navigate(`/`) + const url = new URL(codeServerPage.page.url()) expect(url.pathname).toBe("/") expect(url.search).toBe("")