This tests uses puppeteer to generate screenshots and then pixelmatch to compare them.
- If there are local files to serve - run web server.
- Run
mochawith loaded test cases. - Then, for each test case, open webpage by
puppeteerfor golden and test version, take 2 screenshots. - Compare given screenshots by
pixelmatch, write them in out folder (with HTML pages).
-
Create new file in test-cases folder called
test-case-name.js(test-case-namewill be used as test case name). -
Write your test case in that file.
There is the only 1 requirement for your code - you need to define function called
runTestCase, which takes a container as the first argument and creates there a widget. AlsorunTestCasemight return aPromise. In this case the runner will wait for it before continue a test. (the definition of that function isfunction runTestCase(container: HTMLElement): void | Promise<void> {})
Note that case's file wouldn't prepared/parsed by any bundler/processor (or even by NodeJS), so please pay attention, that you CAN'T require other modules in a test case.
This tests runs against 2 versions of the library - "golden" and "test". Golden is LKG version, test - current tested version of the library.
To run this tests you need use runner.js:
./runner.js ./path/to/golden/standalone/module.js ./path/to/test/standalone/module.jsEach path to the standalone module might be either to a local file (relative/absolute path to a file) or remote file (via http/https). If file is local then local server will be runner to serve that file (see serve-local-files.js module).
-
By default for each test case golden, test and diff screenshots will be written to a
.gendatafolder (can be changed viaCMP_OUT_DIRenv variable). So, you can see what's the difference between screenshots there. -
Also, together with screenshots you can find there HTML pages which was opened to generate that screenshots. But if you test with local files, you cannot open that HTML pages in your browser to debug because there is scripts which are loaded from webserver (which a runner up to runs tests). In that can you can use the following hack.
Let's say you run your tests in that way -
./runner.js ./golden/standalone/module.js ./test/standalone/module.js. After that in.gendata/test-case-name/1.golden.htmlyou can find a HTML page. To open this page properly you can run./tests/e2e/serve-static-files.js golden.js:./golden/standalone/module.js test.js:./test/standalone/module.jsand then open that page in the browser to debug.