Skip to content

Commit a905b11

Browse files
committed
added a test case
1 parent 72a7511 commit a905b11

8 files changed

Lines changed: 86 additions & 3 deletions

File tree

‎tests/frontend-regression-tests/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ all:
44
@casperjs test --concise test-load-from-URL.js
55
@casperjs test --concise test-embedding-demo.js
66
@casperjs test --concise test-java.js
7+
@casperjs test --concise test-testcases.js
78

89
# a micro-test that can run super quickly during development
910
micro:
@@ -18,6 +19,7 @@ verbose:
1819
@casperjs test test-load-from-URL.js
1920
@casperjs test test-embedding-demo.js
2021
@casperjs test test-java.js
22+
@casperjs test test-testcases.js
2123

2224
clean:
2325
find . -name '*.diff.png' | xargs rm -f
53.5 KB
Loading
246 KB
Loading
260 KB
Loading
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Test the 'add a test case' feature
2+
var outputDir = "/test-testcases-outputs"
3+
4+
5+
var baseUrl = 'http://localhost:8003/';
6+
7+
// test visualize.html (mode=edit, mode=display), iframe-embed.html, and live.html
8+
var urlFragments = [
9+
'http://localhost:8003/visualize.html#code=def+multiply(a,+b,+c%29%3A%0A++++return+a+*+b+*+c&mode=edit&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=2&rawInputLstJSON=%5B%5D&testCasesJSON=%5B%22assert+multiply(1,2,3%29+%3D%3D+6%22,%22assert+multiply(3,2,1%29+%3D%3D+5%22,%22assert+multiply(1,2%29+%3D%3D+2%5Cn%23+assert+%3Ctest+condition%3E%22,%22assert+multiply(1,2%29+%3D+3%5Cn%23+assert+%3Ctest+condition%3E%22%5D',
10+
11+
]
12+
13+
14+
var DELAY_MS = 100;
15+
16+
var fs = require('fs');
17+
var path = fs.absolute(fs.workingDirectory + '/phantomcss.js');
18+
var phantomcss = require(path);
19+
20+
casper.test.begin('Testing OPT test cases, loading from URL strings', function (test) {
21+
// boring setup code taken from PhantomCSS demo
22+
phantomcss.init({
23+
rebase: casper.cli.get( "rebase" ),
24+
// SlimerJS needs explicit knowledge of this Casper, and lots of absolute paths
25+
casper: casper,
26+
libraryRoot: fs.absolute( fs.workingDirectory + '' ),
27+
screenshotRoot: fs.absolute( fs.workingDirectory + outputDir + '/screenshots' ),
28+
failedComparisonsRoot: fs.absolute( fs.workingDirectory + outputDir + '/failures' ),
29+
addLabelToFailedImage: false,
30+
});
31+
32+
casper.on('remote.message', function(msg) {this.echo(msg);});
33+
casper.on('error', function (err) {this.die( "PhantomJS has errored: " + err );});
34+
casper.on('resource.error', function (err) {casper.log( 'Resource load error: ' + err, 'warning' );});
35+
36+
37+
// start with a baseline image
38+
casper.start();
39+
casper.viewport(1440, 900);
40+
casper.options.waitTimeout = 10000; // longer default timeout
41+
42+
casper.each(urlFragments, function then(self, e) {
43+
// the TRICK is to first go to a different URL or else the app
44+
// doesn't recognize the URL hashstate change ... which is admittedly a
45+
// bug in OPT right now. but to work around it, simply open a
46+
// different URL between page loads:
47+
self.thenOpen('about:blank');
48+
49+
self.thenOpen(e, function() {
50+
phantomcss.screenshot('#pyInputPane', 'pageLoaded');
51+
52+
casper.wait(DELAY_MS, function() {
53+
this.click("#runAllTestsButton");
54+
casper.wait(2000, function then() {
55+
phantomcss.screenshot('#pyInputPane', 'testsRun');
56+
});
57+
});
58+
59+
casper.thenClick('#vizTestCase_3', function() {
60+
casper.waitFor(function check() {
61+
return this.evaluate(function() {
62+
return document.querySelectorAll("#dataViz").length > 0;
63+
});
64+
}, function then() {
65+
phantomcss.screenshot('.visualizer', 'failingTest');
66+
});
67+
});
68+
});
69+
70+
});
71+
72+
73+
// run all tests:
74+
casper.then(function now_check_the_screenshots() {
75+
phantomcss.compareAll(); // compare screenshots
76+
});
77+
78+
casper.run(function() {
79+
//phantomcss.getExitStatus() // pass or fail?
80+
casper.test.done();
81+
});
82+
});

‎v3/js/opt-testcases.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
204204

205205
if (isViz) {
206206
backendOptionsObj.viz_test_case = true; // just so we can see this in server logs
207+
activateSyntaxErrorSurvey = false; // NASTY global! disable this survey when running test cases since it gets confusing
207208
} else {
208209
backendOptionsObj.run_test_case = true; // just so we can see this in server logs
209210
frontendOptionsObj.runTestCaseCallback = function(trace) {

‎v5-unity/README.txt‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,3 @@ https://github.com/petehunt/webpack-howto
7373
'webpack -d' to include source maps
7474

7575
TODO: always do webpack -p for deploy to production, and add a unique hash
76-
77-
TODO: consider code splitting to split out common parts (e.g., libraries
78-
and unchanging parts) from the specific frontends

‎v5-unity/js/opt-testcases.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
185185

186186
if (isViz) {
187187
backendOptionsObj.viz_test_case = true; // just so we can see this in server logs
188+
activateSyntaxErrorSurvey = false; // NASTY global! disable this survey when running test cases since it gets confusing
188189
} else {
189190
backendOptionsObj.run_test_case = true; // just so we can see this in server logs
190191
frontendOptionsObj.runTestCaseCallback = function(trace) {

0 commit comments

Comments
 (0)