Skip to content

Commit 45a548c

Browse files
committed
tasks: rewrite all test container sh scripts in node
1 parent 1992b57 commit 45a548c

File tree

10 files changed

+87
-77
lines changed

10 files changed

+87
-77
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
"pretest": "node tasks/pretest.js",
3434
"test-jasmine": "karma start test/jasmine/karma.conf.js",
3535
"citest-jasmine": "karma start test/jasmine/karma.ciconf.js",
36-
"test-image": "./tasks/test_image.sh",
37-
"test-export": "./tasks/test_export.sh",
36+
"test-image": "node tasks/test_image.js",
37+
"test-export": "node tasks/test_export.js",
3838
"test-syntax": "node test/syntax_test.js",
3939
"test-bundle": "node tasks/test_bundle.js",
4040
"test": "npm run citest-jasmine && npm run test-image && npm run test-syntax && npm run test-bundle",
4141
"start-test_dashboard": "node devtools/test_dashboard/server.js",
4242
"start-image_viewer": "node devtools/image_viewer/server.js",
4343
"start": "npm run start-test_dashboard",
44-
"baseline": "./tasks/baseline.sh",
44+
"baseline": "node tasks/baseline.js",
4545
"preversion": "npm-link-check && npm dedupe",
4646
"version": "npm run build && git add -A dist src build",
4747
"postversion": "git push && git push --tags"

tasks/baseline.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var exec = require('child_process').exec;
2+
var containerCommands = require('./util/container_commands');
3+
4+
var cmd = containerCommands([
5+
containerCommands.setup,
6+
'node test/image/make_baseline.js ' + process.argv.slice(2).join(' ')
7+
]);
8+
9+
exec(cmd, function(err) {
10+
if(err) throw err;
11+
})
12+
.stdout.pipe(process.stdout);

tasks/baseline.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

tasks/run_in_testbed.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

tasks/test_export.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var exec = require('child_process').exec;
2+
var containerCommands = require('./util/container_commands');
3+
4+
var cmd = containerCommands[process.env.CIRCLECI ? 'runCI' : 'runLocal']([
5+
containerCommands.setup,
6+
'node test/image/export_test.js ' + process.argv.slice(2).join(' ')
7+
]);
8+
9+
exec(cmd, function(err) {
10+
if(err) throw err;
11+
})
12+
.stdout.pipe(process.stdout);

tasks/test_export.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

tasks/test_image.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var exec = require('child_process').exec;
2+
var containerCommands = require('./util/container_commands');
3+
4+
var cmd = containerCommands[process.env.CIRCLECI ? 'runCI' : 'runLocal']([
5+
containerCommands.setup,
6+
'node test/image/compare_pixels_test.js ' + process.argv.slice(2).join(' ')
7+
]);
8+
9+
exec(cmd, function(err) {
10+
if(err) throw err;
11+
})
12+
.stdout.pipe(process.stdout);

tasks/test_image.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

tasks/util/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ module.exports = {
7070
pathToCredentials: path.join(pathToBuild, 'credentials.json'),
7171
pathToSetPlotConfig: path.join(pathToBuild, 'set_plot_config.js'),
7272

73+
testContainerName: process.env.PLOTLYJS_TEST_CONTAINER_NAME || 'imagetest',
74+
testContainerUrl: 'http://localhost:9010/',
75+
testContainerHome: '/var/www/streambed/image_server/plotly.js',
76+
7377
uglifyOptions: {
7478
fromString: true,
7579
mangle: true,

tasks/util/container_commands.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var constants = require('./constants');
2+
3+
var containerCommands = {
4+
cdHome: 'cd ' + constants.testContainerHome,
5+
cpIndex: 'cp -f test/image/index.html ../server_app/index.html',
6+
restart: 'supervisorctl restart nw1',
7+
};
8+
9+
containerCommands.ping = [
10+
'wget',
11+
'--server-response --spider --tries=10 --retry-connrefused',
12+
constants.testContainerUrl + 'ping'
13+
].join(' ');
14+
15+
containerCommands.setup = [
16+
containerCommands.cpIndex,
17+
containerCommands.restart,
18+
containerCommands.ping,
19+
'echo '
20+
].join(' && ');
21+
22+
containerCommands.runLocal = function(commands) {
23+
commands = [containerCommands.cdHome].concat(commands);
24+
25+
return [
26+
'docker exec -i',
27+
constants.testContainerName,
28+
'/bin/bash -c',
29+
'"' + commands.join(' && ') + '"'
30+
].join(' ');
31+
};
32+
33+
containerCommands.runCI = function(commands) {
34+
commands = ['export CIRCLECI=1', containerCommands.cdHome].concat(commands);
35+
36+
return [
37+
'lxc-attach -n',
38+
'$(docker inspect --format \'{{.Id}}\'' + constants.testContainerName + ')',
39+
'-- bash -c',
40+
commands.join(' && ')
41+
].join(' ');
42+
};
43+
44+
module.exports = containerCommands;

0 commit comments

Comments
 (0)