Skip to content

Commit 7ef332a

Browse files
committed
Add wasm CI
1 parent f6a2689 commit 7ef332a

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,35 @@ on: [push]
44
jobs:
55
fmt:
66
runs-on: ubuntu-latest
7-
container: docker://nhooyr/websocket-ci@sha256:549cc2716fd1ff08608b39a52af95a67bf9f490f6f31933cccd94e750985e2dc
7+
container: docker://nhooyr/websocket-ci@sha256:402c8c50cf3bf31561701921ef1b83e3e76f84a8e6efb9864bb92b87ffaf1ac8
88
steps:
99
- uses: actions/checkout@v1
1010
with:
1111
fetch-depth: 1
1212
- run: ./ci/fmt.sh
1313
lint:
1414
runs-on: ubuntu-latest
15-
container: docker://nhooyr/websocket-ci@sha256:549cc2716fd1ff08608b39a52af95a67bf9f490f6f31933cccd94e750985e2dc
15+
container: docker://nhooyr/websocket-ci@sha256:402c8c50cf3bf31561701921ef1b83e3e76f84a8e6efb9864bb92b87ffaf1ac8
1616
steps:
1717
- uses: actions/checkout@v1
1818
with:
1919
fetch-depth: 1
2020
- run: ./ci/lint.sh
2121
test:
2222
runs-on: ubuntu-latest
23-
container: docker://nhooyr/websocket-ci@sha256:549cc2716fd1ff08608b39a52af95a67bf9f490f6f31933cccd94e750985e2dc
23+
container: docker://nhooyr/websocket-ci@sha256:402c8c50cf3bf31561701921ef1b83e3e76f84a8e6efb9864bb92b87ffaf1ac8
2424
steps:
2525
- uses: actions/checkout@v1
2626
with:
2727
fetch-depth: 1
2828
- run: ./ci/test.sh
2929
env:
3030
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
31+
wasm:
32+
runs-on: ubuntu-latest
33+
container: docker://nhooyr/websocket-ci@sha256:402c8c50cf3bf31561701921ef1b83e3e76f84a8e6efb9864bb92b87ffaf1ac8
34+
steps:
35+
- uses: actions/checkout@v1
36+
with:
37+
fetch-depth: 1
38+
- run: ./ci/wasm.sh

ci/image/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ FROM golang:1
22

33
ENV DEBIAN_FRONTEND=noninteractive
44
ENV GOPATH=/root/gopath
5+
ENV PATH=$GOPATH/bin:$PATH
56
ENV GOFLAGS="-mod=readonly"
67
ENV PAGER=cat
78
ENV CI=true
89

910
RUN apt-get update && \
10-
apt-get install -y shellcheck npm && \
11+
apt-get install -y shellcheck npm chromium && \
1112
npm install -g prettier
1213

14+
# https://github.com/golang/go/wiki/WebAssembly#running-tests-in-the-browser
15+
RUN go get github.com/agnivade/wasmbrowsertest && \
16+
mv $GOPATH/bin/wasmbrowsertest $GOPATH/bin/go_js_wasm_exec
17+
18+
1319
RUN git config --global color.ui always
1420

1521
# Cache go modules.

ci/wasm.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
cd "$(dirname "${0}")"
5+
cd "$(git rev-parse --show-toplevel)"
6+
7+
GOOS=js GOARCH=wasm go vet ./...
8+
go install golang.org/x/lint/golint
9+
GOOS=JS GOARCH=wasm golint -set_exit_status ./...
10+
GOOS=js GOARCH=wasm go test ./internal/wsjs

internal/websocketjs/websocketjs.go renamed to internal/wsjs/wsjs.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// +build js
22

3-
// websocketjs implements typed access to the browser javascript WebSocket API.
3+
// Package wsjs implements typed access to the browser javascript WebSocket API.
44
// https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
5-
package websocketjs
5+
package wsjs
66

77
import (
88
"context"
@@ -101,8 +101,14 @@ type MessageEvent struct {
101101

102102
func (c *WebSocket) OnMessage(fn func(m MessageEvent)) {
103103
c.addEventListener("message", func(e js.Value) {
104+
var data []byte
105+
104106
arrayBuffer := e.Get("data")
105-
data := extractArrayBuffer(arrayBuffer)
107+
if arrayBuffer.Type() == js.TypeString {
108+
data = []byte(arrayBuffer.String())
109+
} else {
110+
data = extractArrayBuffer(arrayBuffer)
111+
}
106112

107113
me := MessageEvent{
108114
Data: data,

internal/websocketjs/websocketjs_test.go renamed to internal/wsjs/wsjs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build js
22

3-
package websocketjs
3+
package wsjs
44

55
import (
66
"context"

0 commit comments

Comments
 (0)