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

How to write tests? #144

Open
breml opened this issue May 10, 2018 · 3 comments
Open

How to write tests? #144

breml opened this issue May 10, 2018 · 3 comments

Comments

@breml
Copy link

breml commented May 10, 2018

I tried to write tests in combination with this package. I tired with this minimal file (react_test.go):

package testreact

import (
	"testing"

	_ "myitcv.io/react"
)

func TestReact(t *testing.T) {
	t.Log("OK")
}

If I execute go test ., the following output is given:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4e6082]

goroutine 1 [running]:
github.com/gopherjs/gopherjs/js.(*Object).Get(0x0, 0x5311e3, 0x5, 0xc4200543e0)
	/home/lubr/code/go/src/github.com/gopherjs/gopherjs/js/js.go:32 +0x22
FAIL	github.com/breml/reacttest/test	0.003s

If I use gopherjs tes ., then the output is:

gopherjs: Source maps disabled. Install source-map-support module for nice stack traces. See https://github.com/gopherjs/gopherjs#gopherjs-run-gopherjs-test.
/home/lubr/code/go/src/github.com/breml/reacttest/test/test.629576433:24995
var o=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,l,u=r(e),c=1;c<arguments.length;c++){n=Object(arguments[c]);for(var s in n)a.call(n,s)&&(u[s]=n[s]);if(o){l=o(n);for(var f=0;f<l.length;f++)i.call(n,l[f])&&(u[l[f]]=n[l[f]])}}return u}},function(e,t,n){"use strict";var r={};e.exports=r},function(e,t,n){"use strict";function r(e){return function(){return e}}var o=function(){};o.thatReturns=r

ReferenceError: window is not defined
    at Object.t (/home/lubr/code/go/src/github.com/breml/reacttest/test/test.629576433:24995:1138)
    at t (/home/lubr/code/go/src/github.com/breml/reacttest/test/test.629576433:24990:146)
    at /home/lubr/code/go/src/github.com/breml/reacttest/test/test.629576433:24990:503
    at /home/lubr/code/go/src/github.com/breml/reacttest/test/test.629576433:24990:512
    at Object.<anonymous> (/home/lubr/code/go/src/github.com/breml/reacttest/test/test.629576433:25012:5)
    at Object.<anonymous> (/home/lubr/code/go/src/github.com/breml/reacttest/test/test.629576433:35738:4)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3
FAIL	github.com/breml/reacttest/test	0.299s
@myitcv
Copy link
Owner

myitcv commented May 11, 2018

@breml good question.

gopherjs test uses the Node environment; hence the window global is not available.

For this reason I wrote (the very basic) myitcv.io/gjbt which enables you to run tests within a headless Chrome instance.

The myitcv.io/react tests themselves use this approach.

Skeleton tests for all of the generated elements are themselves also generated in case you need any inspiration, e.g. the <a> element tests.

Let me know how you get on.

@breml
Copy link
Author

breml commented May 13, 2018

@myitcv I tried gjbt, but this does not yet look clean to me.

I installed chromedriver, added the init_test.go file as suggested and run gjbt .. I then get this output:

ok  	github.com/breml/reacttest/test	0.046s
panic: failed to retrieve logs: unexpected response: {"sessionId":"a6fa970438e2285d182fe582c707e7a2","status":6,"value":{"message":"no such session\n  (Driver info: chromedriver=2.9.248304,platform=Linux 4.4.0-122-generic x86_64)"}}

goroutine 1 [running]:
main.main()
	/home/lubr/code/go/src/github.com/myitcv/gjbt/main.go:163 +0xe8b

It looks like the test have been executed (and are successful), but I still get the above mentioned panic. Do you have an idea why this happens?

@myitcv
Copy link
Owner

myitcv commented May 20, 2018

@breml there have been a few more commits recently to gjbt (as well as some improve documentation) which probably fix the issue you've seen. Please can you give it another try?

In particular, the README now lists requirements:

https://github.com/myitcv/gjbt

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants