Skip to content
This repository was archived by the owner on Aug 27, 2018. It is now read-only.

Commit 4257dda

Browse files
authored
Merge pull request #112 from myitcv/repin_gjbt
Repin gjbt
2 parents da97023 + e9f359c commit 4257dda

File tree

10 files changed

+140
-2
lines changed

10 files changed

+140
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
myitcv.io/gjbt
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: go
2+
3+
addons:
4+
chrome: beta
5+
6+
go:
7+
- 1.x
8+
9+
go_import_path: myitcv.io/gjbt
10+
11+
before_script:
12+
- curl -s https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip > /tmp/chromedriver_linux64.zip
13+
- unzip -d /tmp/chromedriver_linux64 /tmp/chromedriver_linux64.zip
14+
- export PATH=$PATH:/tmp/chromedriver_linux64
15+
16+
install: true
17+
18+
script:
19+
- ./_scripts/run_tests.sh
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
./_vendor/src/golang.org/x/sys 13d03a9a82fba647c21a0ef8fba44a795d0f0835 https://go.googlesource.com/sys
2+
./_vendor/src/golang.org/x/crypto 88942b9c40a4c9d203b82b3731787b672d6e809b https://go.googlesource.com/crypto
3+
./_vendor/src/golang.org/x/tools 77106db15f689a60e7d4e085d967ac557b918fb2 https://go.googlesource.com/tools
4+
./_vendor/src/github.com/gopherjs/gopherjs 82b322028c96512b15077093b16a5f1c7ea897ac git@github.com:gopherjs/gopherjs
5+
./_vendor/src/github.com/kisielk/gotool 80517062f582ea3340cd4baf70e86d539ae7d84d git@github.com:kisielk/gotool
6+
./_vendor/src/github.com/fsnotify/fsnotify c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9 git@github.com:fsnotify/fsnotify
7+
./_vendor/src/github.com/spf13/cobra a1f051bc3eba734da4772d60e2d677f47cf93ef4 git@github.com:spf13/cobra
8+
./_vendor/src/github.com/spf13/pflag ee5fd03fd6acfd43e44aea0b4135958546ed8e73 git@github.com:spf13/pflag
9+
./_vendor/src/github.com/sclevine/agouti 6ada53bb069e86f8baf0953d4f0ddac081bc7610 git@github.com:sclevine/agouti
10+
./_vendor/src/github.com/neelance/astrewrite 99348263ae862cc230986ce88deaddbf7edcc034 git@github.com:neelance/astrewrite
11+
./_vendor/src/github.com/neelance/sourcemap 8c68805598ab8d5637b1a72b5f7d381ea0f39c31 git@github.com:neelance/sourcemap
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.com/gopherjs/gopherjs
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
### `gjbt`
22

3-
`gjbt` is a simple (temporary) wrapper for GopherJS to run tests in (Chrome) your browser. `gopherjs test` generally
4-
runs your tests under NodeJS; `gjbt` instead runs these tests in Chrome.
3+
`gjbt` is a simple (temporary) wrapper for GopherJS to run tests in Chrome as opposed to NodeJS. It should be considered
4+
to be a direct replacement for `gopherjs test`.
5+
6+
Running your tests in Chrome has a number of benefits:
7+
8+
* it is almost certainly the VM in which your code will ultimately run
9+
* you have full access to the DOM
10+
11+
Example:
12+
13+
```
14+
$ gjbt myitcv.io/gjbt
15+
ok myitcv.io/gjbt 0.273s
16+
PASS
17+
```
18+
19+
### Requirements
20+
21+
(For now) A small wrapper is required around `TestMain` in each package to be tested. It is sufficient to copy
22+
`init_test.go`, modifying the test package name, to your package.
23+
24+
### DOM Access
25+
26+
See [the tests in `myitcv.io/react`](https://github.com/myitcv/react/blob/master/a_elem_test.go) for examples of DOM
27+
access.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2016 Paul Jolly <paul@myitcv.org.uk>, all rights reserved.
2+
# Use of this document is governed by a license found in the LICENSE document.
3+
4+
set -u
5+
set -o pipefail
6+
7+
# The following must be set _before_ the trap in order that the trap also applies within
8+
# function bodies
9+
#
10+
# See https://www.gnu.org/software/bash/manual/html_node/Shell-Functions.html#Shell-Functions
11+
set -o errtrace
12+
13+
shopt -s globstar
14+
shopt -s extglob
15+
16+
error() {
17+
local lineno="$1"
18+
local file="$2"
19+
20+
# intentional so we can test BASH_SOURCE
21+
if [[ -n "$file" ]] ; then
22+
echo "Error on line $file:$lineno"
23+
fi
24+
25+
exit 1
26+
}
27+
28+
trap 'set +u; error "${LINENO}" "${BASH_SOURCE}"' ERR
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2016 Paul Jolly <paul@myitcv.org.uk>, all rights reserved.
4+
# Use of this document is governed by a license found in the LICENSE document.
5+
6+
source "${BASH_SOURCE%/*}/common.bash"
7+
8+
export PATH=$PWD/_vendor/bin:$GOPATH/bin:$PATH
9+
export GOPATH=$PWD/_vendor:$GOPATH
10+
11+
# ensure we are in the right directory
12+
cd "${BASH_SOURCE%/*}/.."
13+
14+
for i in $(cat .vendored_bin_deps .bin_deps)
15+
do
16+
go install $i
17+
done
18+
19+
gjbt myitcv.io/gjbt
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// +build js
2+
3+
package main_test
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/gopherjs/gopherjs/js"
10+
)
11+
12+
func TestMain(m *testing.M) {
13+
i := m.Run()
14+
15+
js.Global.Call("eval", fmt.Sprintf("window.$GopherJSTestResult = %v", i))
16+
}

_vendor/src/myitcv.io/gjbt/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// gjbt is a simple (temporary) wrapper for GopherJS to run tests in Chrome as
2+
// opposed to NodeJS.
13
package main
24

35
import (
@@ -107,6 +109,7 @@ func main() {
107109
err = cmd.Run()
108110
if err != nil {
109111
os.Remove(tf.Name())
112+
fmt.Printf("%v\n", err)
110113
failed = true
111114
continue
112115
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// +build js
2+
3+
package main_test
4+
5+
import (
6+
"testing"
7+
8+
"github.com/gopherjs/gopherjs/js"
9+
)
10+
11+
func TestWindow(t *testing.T) {
12+
w := js.Global.Get("window")
13+
14+
if w == nil {
15+
t.Fatalf("expected to be able to access window")
16+
}
17+
}

0 commit comments

Comments
 (0)