The tests in this folder are run via jake karma and will be executed in a browser.
Tests for the Blockly compiler take a .blocks file as input and compare
the output against a baseline .ts file. To generate those files:
- Add the required block definitions in the
test-librarydirectory. Make sure you add the.tsfile you create topxt.json. Note: do not add any C++ files, this library only accepts TypeScript! - Create the
.blocksfile for the test. There is no easy way to do it, but this is the method I follow: a. Copy the code you added in step 1 to some target (likepxt-sample) b. Runpxt servein that target and create your test case in the editor c. Inside theprojectsdirectory of that target, a directory should have been created for the new project you just made in the editor. Grab themain.blocksfile from that directory. - Place the
.blocksfile in thecasessubdirectory. - Add the expected result
.tsfile with the same name (but different file extension) to thebaselinesdirectory - In
test.spec.ts, add a test case for your new files. Copy the other ones in that file and give it a relevant message.
To debug the Karma tests, run jake karma-debug. This will launch the tests in the browser like usual but the browser will not close when the tests are finished. In the upper-right corner of the browser window, click on the button labelled "Debug". That will cause a new tab to open in which you can debug using the developer tools. The test files should be available in that window (look for test.spec.js and commentparsing.spec.js). Refresh the tab to re-run the tests.
Note: If you run jake karma-debug, the browser window that spawns will be un-closeable (if you try to close it, Karma will interpret that as a browser crash and immediately reopen it). To close the window, CTRL-c the process in the terminal.