Skip to content

Commit a09d45f

Browse files
committed
added a micro test
1 parent 55a7a65 commit a09d45f

8 files changed

Lines changed: 136 additions & 5 deletions

File tree

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
all:
2-
@casperjs test test-visualize-html.js
3-
@casperjs test test-load-from-URL.js
4-
@casperjs test test-embedding-demo.js
2+
casperjs test --concise test-micro.js
3+
casperjs test --concise test-visualize-html.js
4+
casperjs test --concise test-load-from-URL.js
5+
casperjs test --concise test-embedding-demo.js
6+
7+
# a micro-test that can run super quickly during development
8+
micro:
9+
casperjs test --concise test-micro.js
10+
11+
verbose:
12+
casperjs test test-micro.js
13+
casperjs test test-visualize-html.js
14+
casperjs test test-load-from-URL.js
15+
casperjs test test-embedding-demo.js

‎tests/frontend-regression-tests/phantomcss.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,7 @@ function initClient() {
635635
function _onPass( test ) {
636636
// pgbovine - briefer pass msgs
637637
//console.log( '\n' );
638-
//casper.test.pass( 'No changes found for screenshot ' + test.filename );
639-
casper.test.pass('yay');
638+
casper.test.pass( 'No changes found for screenshot ' + test.filename );
640639
}
641640

642641
function _onFail( test ) {
102 KB
Loading
262 KB
Loading
87.5 KB
Loading
89.5 KB
Loading
244 KB
Loading
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// a micro-test that can run super quickly between code edits, for sanity checks
2+
var outputDir = "/test-micro-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+
// Python
10+
'#code=%23%20Higher-order%20functions%0A%23%20Adapted%20from%20MIT%206.01%20course%20notes%20(Section%20A.2.2%29%0A%23%20http%3A//mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf%0A%0Adef%20summation(low,%20high,%20f,%20next%29%3A%0A%20%20%20%20s%20%3D%200%0A%20%20%20%20x%20%3D%20low%0A%20%20%20%20while%20x%20%3C%3D%20high%3A%0A%20%20%20%20%20%20%20%20s%20%3D%20s%20%2B%20f(x%29%0A%20%20%20%20%20%20%20%20x%20%3D%20next(x%29%0A%20%20%20%20return%20s%0A%0Adef%20sumsquares(low,%20high%29%3A%0A%20%20%20%20return%20summation(low,%20high,%20lambda%20x%3A%20x**2,%20lambda%20x%3A%20x%2B1%29%0A%0Aprint(sumsquares(1,%2010%29%29&curInstr=41&origin=opt-frontend.js&py=2&rawInputLstJSON=%5B%5D',
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 page loads 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+
var urlFrag = e;
44+
var visualizeHtmlEditMode = baseUrl + 'visualize.html' + e + '&mode=edit';
45+
var visualizeHtmlDisplayMode = baseUrl + 'visualize.html' + e + '&mode=display';
46+
var iframeEmbedHtml = baseUrl + 'iframe-embed.html' + e;
47+
var liveHtml = baseUrl + 'live.html' + e + '&mode=display'; // annoying hack - need mode=display to jump to a step in curInstr
48+
49+
// the TRICK is to first go to a different URL or else the app
50+
// doesn't recognize the URL hashstate change ... which is admittedly a
51+
// bug in OPT right now. but to work around it, simply open a
52+
// different URL between page loads:
53+
self.thenOpen('about:blank');
54+
55+
self.thenOpen(visualizeHtmlEditMode, function() {
56+
phantomcss.screenshot('#pyInputPane', 'testEditModeEditor');
57+
58+
casper.wait(DELAY_MS, function() {
59+
this.click("#executeBtn");
60+
// after clicking on executeBtn, wait for the dataViz div to appear
61+
// because that means the visualizer has rendered:
62+
casper.waitFor(function check() {
63+
return this.evaluate(function() {
64+
return document.querySelectorAll("#dataViz").length > 0;
65+
});
66+
}, function then() {
67+
// jump to the last step, then take a screenshot
68+
casper.click('#jmpLastInstr');
69+
phantomcss.screenshot('.visualizer', 'testEditModeVisualizer');
70+
});
71+
});
72+
});
73+
74+
75+
self.thenOpen('about:blank');
76+
self.thenOpen(visualizeHtmlDisplayMode, function() {
77+
casper.waitFor(function check() {
78+
return this.evaluate(function() {
79+
return document.querySelectorAll("#dataViz").length > 0;
80+
});
81+
}, function then() {
82+
phantomcss.screenshot('.visualizer', 'testDisplayMode');
83+
});
84+
});
85+
86+
87+
self.thenOpen('about:blank');
88+
self.thenOpen(iframeEmbedHtml, function() {
89+
casper.waitFor(function check() {
90+
return this.evaluate(function() {
91+
return document.querySelectorAll("#dataViz").length > 0;
92+
});
93+
}, function then() {
94+
phantomcss.screenshot('.visualizer', 'testIframeEmbed');
95+
});
96+
});
97+
98+
99+
self.thenOpen('about:blank');
100+
self.thenOpen(liveHtml, function() {
101+
casper.waitFor(function check() {
102+
return this.evaluate(function() {
103+
return document.querySelectorAll("#dataViz").length > 0;
104+
});
105+
}, function then() {
106+
phantomcss.screenshot('body', 'testLiveMode'); // full-page screenshot!
107+
});
108+
});
109+
});
110+
111+
112+
// run all tests:
113+
casper.then(function now_check_the_screenshots() {
114+
phantomcss.compareAll(); // compare screenshots
115+
});
116+
117+
casper.run(function() {
118+
//phantomcss.getExitStatus() // pass or fail?
119+
casper.test.done();
120+
});
121+
});

0 commit comments

Comments
 (0)