Skip to content
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

fix(testing): revert change & fix playwright tests #4310

Merged
merged 39 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d1e36dd
fix(testing): revert change & fix playwright tests
jsjoeio Oct 4, 2021
53743af
fix(constants): add type to import statement
jsjoeio Oct 5, 2021
1e64920
refactor(e2e): delete browser test
jsjoeio Oct 6, 2021
35381c0
chore(e2e): use 1 worker for e2e test
jsjoeio Oct 7, 2021
4805186
revert(vscode): add missing route with redirect
jsjoeio Oct 7, 2021
0b080f5
chore(vscode): update to latest fork
jsjoeio Oct 7, 2021
d7e7e43
Touch up compilation step.
GirlBossRush Oct 15, 2021
717bb79
Bump vendor.
GirlBossRush Oct 15, 2021
5a28626
Fix VS Code minification step
code-asher Oct 18, 2021
e22a0e5
Move ClientConfiguration to common
code-asher Oct 13, 2021
036ee86
Ensure lib directory exists before curling
code-asher Oct 13, 2021
1acb0a1
Update incorrect e2e test help output
code-asher Oct 13, 2021
467eaef
Add back extension compilation step
code-asher Oct 19, 2021
fd7f1ec
Include missing resources in release
code-asher Oct 19, 2021
70edeb9
Set quality property in product configuration
code-asher Oct 19, 2021
6208a2b
Update VS Code
code-asher Oct 20, 2021
2d628cc
Bump vscode.
GirlBossRush Oct 21, 2021
891eb61
Bump.
GirlBossRush Oct 21, 2021
e81a37e
Bump.
GirlBossRush Oct 21, 2021
b4bda04
Use CLI directly.
GirlBossRush Oct 21, 2021
353c2a1
Update tests to reflect new upstream behavior.
GirlBossRush Oct 7, 2021
c1b40a5
Move unit tests to after the build
code-asher Oct 21, 2021
fd42387
Upgrade proxy-agent dependencies
code-asher Oct 21, 2021
dd8124f
Symlink VS Code output directory before unit tests
code-asher Oct 21, 2021
6efc7b4
Fix issues surrounding persistent processes between tests.
GirlBossRush Oct 22, 2021
6d777c1
Update VS Code cache directories
code-asher Oct 22, 2021
64b6f71
Move test symlink to script
code-asher Oct 22, 2021
752fe7c
Fix listening on a socket
code-asher Oct 22, 2021
0cfd245
Update VS Code
code-asher Oct 26, 2021
51a48ba
Standardize disposals
code-asher Oct 26, 2021
fc81fc3
Dispose HTTP server
code-asher Oct 26, 2021
070d131
Dispose app on exit
code-asher Oct 26, 2021
a343efe
Fix logging link errors
code-asher Oct 26, 2021
8857e67
Update regex used by e2e to extract address
code-asher Oct 27, 2021
7a52cb8
Log browser console in e2e tests
code-asher Oct 27, 2021
44602cc
Add base back to login page
code-asher Oct 28, 2021
6fbbd83
Remove login page test
code-asher Oct 28, 2021
f4a8c9d
Use path.posix for static base
code-asher Oct 28, 2021
02f4e00
Add test for invalid password
code-asher Oct 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
name: Pre-build checks
runs-on: ubuntu-latest
timeout-minutes: 15
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -54,14 +52,6 @@ jobs:
run: yarn lint
if: success()

- name: Run code-server unit tests
run: yarn test:unit
if: success()

- name: Upload coverage report to Codecov
run: yarn coverage
if: success()

audit-ci:
name: Run audit-ci
needs: prebuild
Expand Down Expand Up @@ -98,6 +88,8 @@ jobs:
needs: prebuild
runs-on: ubuntu-latest
timeout-minutes: 30
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -146,14 +138,25 @@ jobs:
path: |
vendor/modules/code-oss-dev/.build
vendor/modules/code-oss-dev/out-build
vendor/modules/code-oss-dev/out-vscode
vendor/modules/code-oss-dev/out-vscode-min
key: vscode-build-${{ steps.vscode-rev.outputs.rev }}
vendor/modules/code-oss-dev/out-vscode-server
vendor/modules/code-oss-dev/out-vscode-server-min
key: vscode-server-build-${{ steps.vscode-rev.outputs.rev }}

- name: Build vscode
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
run: yarn coverage
if: success()

# The release package does not contain any native modules
# and is neutral to architecture/os/libc version.
- name: Create release package
Expand Down
2 changes: 2 additions & 0 deletions ci/build/build-code-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ main() {
source ./ci/lib.sh
OS="$(uname | tr '[:upper:]' '[:lower:]')"

mkdir -p ./lib

if ! [ -f ./lib/coder-cloud-agent ]; then
echo "Downloading the cloud agent..."

Expand Down
8 changes: 4 additions & 4 deletions ci/build/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ EOF
bundle_vscode() {
mkdir -p "$VSCODE_OUT_PATH"
rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH"
rsync "$VSCODE_SRC_PATH/out-vscode${MINIFY:+-min}/" "$VSCODE_OUT_PATH/out"
rsync "$VSCODE_SRC_PATH/out-vscode-server${MINIFY:+-min}/" "$VSCODE_OUT_PATH/out"

rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions"
if [ "$KEEP_MODULES" = 0 ]; then
Expand All @@ -80,9 +80,8 @@ bundle_vscode() {
rsync "$VSCODE_SRC_PATH/extensions/yarn.lock" "$VSCODE_OUT_PATH/extensions"
rsync "$VSCODE_SRC_PATH/extensions/postinstall.js" "$VSCODE_OUT_PATH/extensions"

mkdir -p "$VSCODE_OUT_PATH/resources/"{linux,web}
rsync "$VSCODE_SRC_PATH/resources/linux/" "$VSCODE_OUT_PATH/resources/linux/"
rsync "$VSCODE_SRC_PATH/resources/web/" "$VSCODE_OUT_PATH/resources/web/"
mkdir -p "$VSCODE_OUT_PATH/resources/"
rsync "$VSCODE_SRC_PATH/resources/" "$VSCODE_OUT_PATH/resources/"

# Add the commit and date and enable telemetry. This just makes telemetry
# available; telemetry can still be disabled by flag or setting.
Expand All @@ -91,6 +90,7 @@ bundle_vscode() {
{
"enableTelemetry": true,
"commit": "$(git rev-parse HEAD)",
"quality": "stable",
"date": $(jq -n 'now | todate')
}
EOF
Expand Down
10 changes: 3 additions & 7 deletions ci/build/build-vscode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ main() {

cd vendor/modules/code-oss-dev

yarn gulp compile-build compile-extensions-build compile-extension-media compile-web

yarn gulp optimize --gulpfile ./coder.js

if [[ $MINIFY ]]; then
yarn gulp minify --gulpfile ./coder.js
fi
# extensions-ci compiles extensions and includes their media.
# compile-web compiles web extensions. TODO: Unsure if used.
yarn gulp extensions-ci compile-web "vscode-server${MINIFY:+-min}"
}

main "$@"
3 changes: 3 additions & 0 deletions ci/build/npm-postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ main() {
esac

OS="$(uname | tr '[:upper:]' '[:lower:]')"

mkdir -p ./lib

if curl -fsSL "https://github.com/cdr/cloud-agent/releases/latest/download/cloud-agent-$OS-$ARCH" -o ./lib/coder-cloud-agent; then
chmod +x ./lib/coder-cloud-agent
else
Expand Down
11 changes: 9 additions & 2 deletions ci/dev/test-e2e.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

help() {
echo >&2 " You can build with 'yarn watch' or you can build a release"
echo >&2 " For example: 'yarn build && yarn build:vscode && KEEP_MODULES=1 yarn release'"
echo >&2 " Then 'CODE_SERVER_TEST_ENTRY=./release yarn test:e2e'"
echo >&2 " You can manually run that release with 'node ./release'"
}

main() {
cd "$(dirname "$0")/../.."

Expand All @@ -21,13 +28,13 @@ main() {
# wrong (native modules version issues, incomplete build, etc).
if [[ ! -d $dir/out ]]; then
echo >&2 "No code-server build detected"
echo >&2 "You can build it with 'yarn build' or 'yarn watch'"
help
exit 1
fi

if [[ ! -d $dir/vendor/modules/code-oss-dev/out ]]; then
echo >&2 "No VS Code build detected"
echo >&2 "You can build it with 'yarn build:vscode' or 'yarn watch'"
help
exit 1
fi

Expand Down
18 changes: 16 additions & 2 deletions ci/dev/test-unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@ set -euo pipefail

main() {
cd "$(dirname "$0")/../.."
cd test/unit/node/test-plugin

source ./ci/lib.sh

pushd test/unit/node/test-plugin
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.
local vscode="vendor/modules/code-oss-dev"
local link="$vscode/out"
local target="out-build"
if [[ ! -e $link ]] && [[ -d $vscode/$target ]]; then
ln -s "$target" "$link"
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.
cd "$OLDPWD"
CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@"
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"release:prep": "./ci/build/release-prep.sh",
"test:e2e": "./ci/dev/test-e2e.sh",
"test:standalone-release": "./ci/build/test-standalone-release.sh",
"test:unit": "./ci/dev/test-unit.sh",
"test:unit": "./ci/dev/test-unit.sh --forceExit --detectOpenHandles",
"test:scripts": "./ci/dev/test-scripts.sh",
"package": "./ci/build/build-packages.sh",
"postinstall": "./ci/dev/postinstall.sh",
Expand Down
9 changes: 9 additions & 0 deletions src/browser/pages/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h1 class="main">Welcome to code-server</h1>
<div class="content">
<form class="login-form" method="post">
<input class="user" type="text" autocomplete="username" />
<input id="base" type="hidden" name="base" value="/" />
<div class="field">
<input
required
Expand All @@ -47,5 +48,13 @@ <h1 class="main">Welcome to code-server</h1>
</div>
</div>
</div>
<script>
// Inform the backend about the path since the proxy might have rewritten
// it out of the headers and cookies must be set with absolute paths.
const el = document.getElementById("base")
if (el) {
el.value = window.location.pathname
}
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/common/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { logger } from "@coder/logger"
export type Callback<T, R = void | Promise<void>> = (t: T, p: Promise<void>) => R

export interface Disposable {
dispose(): void
dispose(): void | Promise<void>
}

export interface Event<T> {
Expand Down
31 changes: 1 addition & 30 deletions src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,6 @@ export const resolveBase = (base?: string): string => {
return normalize(url.pathname)
}

/**
* Get client-side configuration embedded in the HTML or query params.
*/
export const getClientConfiguration = <T extends CodeServerLib.ClientConfiguration>(): T => {
let config: T
try {
config = JSON.parse(document.getElementById("coder-options")!.getAttribute("data-settings")!)
} catch (error) {
config = {} as T
}

// You can also pass options in stringified form to the options query
// variable. Options provided here will override the ones in the options
// element.
const params = new URLSearchParams(location.search)
const queryOpts = params.get("options")
if (queryOpts) {
config = {
...config,
...JSON.parse(queryOpts),
}
}

config.base = resolveBase(config.base)
config.csStaticBase = resolveBase(config.csStaticBase)

return config
}

/**
* Wrap the value in an array if it's not already an array. If the value is
* undefined return an empty array.
Expand All @@ -94,7 +65,7 @@ export const arrayify = <T>(value?: T | T[]): T[] => {
}

// TODO: Might make sense to add Error handling to the logger itself.
export function logError(logger: { error: (msg: string) => void }, prefix: string, err: Error | string): void {
export function logError(logger: { error: (msg: string) => void }, prefix: string, err: unknown): void {
if (err instanceof Error) {
logger.error(`${prefix}: ${err.message} ${err.stack}`)
} else {
Expand Down
42 changes: 30 additions & 12 deletions src/node/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ import express, { Express } from "express"
import { promises as fs } from "fs"
import http from "http"
import * as httpolyglot from "httpolyglot"
import { Disposable } from "../common/emitter"
import * as util from "../common/util"
import { DefaultedArgs } from "./cli"
import { disposer } from "./http"
import { isNodeJSErrnoException } from "./util"
import { handleUpgrade } from "./wsRouter"

type ListenOptions = Pick<DefaultedArgs, "socket" | "port" | "host">

export interface App extends Disposable {
/** Handles regular HTTP requests. */
router: Express
/** Handles websocket requests. */
wsRouter: Express
/** The underlying HTTP server. */
server: http.Server
}

const listen = (server: http.Server, { host, port, socket }: ListenOptions) => {
return new Promise<void>(async (resolve, reject) => {
server.on("error", reject)
Expand Down Expand Up @@ -41,41 +52,48 @@ const listen = (server: http.Server, { host, port, socket }: ListenOptions) => {
/**
* Create an Express app and an HTTP/S server to serve it.
*/
export const createApp = async (args: DefaultedArgs): Promise<[Express, Express, http.Server]> => {
const app = express()

app.use(compression())
export const createApp = async (args: DefaultedArgs): Promise<App> => {
const router = express()
router.use(compression())

const server = args.cert
? httpolyglot.createServer(
{
cert: args.cert && (await fs.readFile(args.cert.value)),
key: args["cert-key"] && (await fs.readFile(args["cert-key"])),
},
app,
router,
)
: http.createServer(app)
: http.createServer(router)

const dispose = disposer(server)

await listen(server, args)

const wsApp = express()
handleUpgrade(wsApp, server)
const wsRouter = express()
handleUpgrade(wsRouter, server)

return [app, wsApp, server]
return { router, wsRouter, server, dispose }
}

/**
* Get the address of a server as a string (protocol *is* included) while
* ensuring there is one (will throw if there isn't).
*
* The address might be a URL or it might be a pipe or socket path.
*/
export const ensureAddress = (server: http.Server): string => {
export const ensureAddress = (server: http.Server, protocol: string): URL | string => {
const addr = server.address()

if (!addr) {
throw new Error("server has no address")
throw new Error("Server has no address")
}

if (typeof addr !== "string") {
return `http://${addr.address}:${addr.port}`
return new URL(`${protocol}://${addr.address}:${addr.port}`)
}

// If this is a string then it is a pipe or Unix socket.
return addr
}

Expand Down
Loading