Skip to content

Commit 39f20f5

Browse files
committed
extended testcases to cover new functionality
1 parent 4a06071 commit 39f20f5

File tree

3 files changed

+80
-35
lines changed

3 files changed

+80
-35
lines changed

extension.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,28 @@ module.exports = new Extension({
3838
* @param {object} tokens Original tokens for this extension
3939
*/
4040
function _extendTokens(args, tokens) {
41-
// if we have an args object, there might be properties we want to
42-
// migrate into the tokens object.
43-
if (typeof(args) === 'object') {
41+
var _tokens = {},
42+
_args = args,
43+
expectedKeys = ['flags'];
4444

45-
var _tokens = {},
46-
expectedKeys = ['flags'];
47-
48-
// shallow-copy the original tokens object
49-
for (let key in tokens) {
50-
_tokens[key] = tokens[key];
51-
}
52-
53-
// copy expected arguments from args to the new tokens object
54-
// defaulting to an emptystring
55-
for (let key of expectedKeys) {
56-
// prepend keys with a dollar-sign for template-replacement
57-
_tokens['$'+key] = args[key] || '';
58-
}
45+
// if args is not an object, we'll just use an empty one
46+
if (typeof(args) !== 'object') {
47+
_args = {};
48+
}
5949

60-
return _tokens;
50+
// shallow-copy the original tokens object
51+
for (let key in tokens) {
52+
_tokens[key] = tokens[key];
6153
}
62-
// otherwise we just pass through the original tokens object
63-
else {
64-
return tokens;
54+
55+
// copy expected arguments from args to the new tokens object
56+
// defaulting to an emptystring
57+
for (let key of expectedKeys) {
58+
// prepend keys with a dollar-sign for template-replacement
59+
_tokens['$'+key] = _args[key] || '';
6560
}
61+
62+
return _tokens;
6663
}
6764

6865
/**

test/.xinitrc.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exec /usr/bin/chromium --noerrdialogs --kiosk --incognito $url
1+
exec /usr/bin/chromium --noerrdialogs --kiosk --incognito $flags "$url"

test/extension.spec.js

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ describe('instantiation', function() {
1111
});
1212

1313
describe('properties', function() {
14-
after(function(done) {
15-
exec('rm ' + __dirname + '/.xinitrc', done);
16-
});
17-
1814
it('should include all required format properties', function() {
1915
var format = WebsiteExtension.props.format;
2016

@@ -37,29 +33,81 @@ describe('properties', function() {
3733
assert(format.end_command);
3834
assert(typeof format.end_command === 'string');
3935
});
36+
});
4037

41-
it('start_command should update .xinitrc file with supplied token', function(done) {
42-
var format = WebsiteExtension.props.format,
43-
command,
44-
expected = 'exec /usr/bin/chromium --noerrdialogs --kiosk --incognito http://test.com';
38+
describe('start_command', function() {
39+
var expectedDefault = 'exec /usr/bin/chromium --noerrdialogs --kiosk --incognito "http://test.com"';
4540

46-
// use test .xinitrc
47-
format.xinitrcTplPath = __dirname + '/.xinitrc.tpl';
48-
format.xinitrcFinalPath = format.xinitrcTplPath.replace('.tpl', '');
41+
after(function(done) {
42+
exec('rm ' + __dirname + '/.xinitrc', done);
43+
});
44+
45+
it('should update .xinitrc file with supplied token', function(done) {
46+
var format = getTestFormat(),
47+
command;
4948

5049
// replace $url token with url string
5150
command = format.start_command({}, {
5251
$url: 'http://test.com'
5352
});
5453

5554
assert(typeof command === 'string');
55+
checkXinitrc(format.xinitrcFinalPath, expectedDefault, done);
56+
});
57+
it('should not accept undefined args parameter', function(done) {
58+
var format = getTestFormat(),
59+
command;
60+
61+
// replace $url token with url string
62+
command = format.start_command(undefined, {
63+
$url: 'http://test.com'
64+
});
65+
66+
assert(typeof command === 'string');
67+
checkXinitrc(format.xinitrcFinalPath, expectedDefault, done);
68+
});
69+
it('should update .xinitrc with optional args', function(done) {
70+
var format = getTestFormat(),
71+
command,
72+
expected = 'exec /usr/bin/chromium --noerrdialogs --kiosk --incognito --allow-insecure-localhost "http://test.com"';
5673

57-
fs.readFile(format.xinitrcFinalPath, 'utf8', function(err, data) {
74+
// replace $url token with url string
75+
command = format.start_command({flags:'--allow-insecure-localhost'}, {
76+
$url: 'http://test.com'
77+
});
78+
79+
assert(typeof command === 'string');
80+
checkXinitrc(format.xinitrcFinalPath, expected, done);
81+
});
82+
it('should ignore unsupported args', function(done) {
83+
var format = getTestFormat(),
84+
command;
85+
86+
// replace $url token with url string
87+
command = format.start_command({random:'args'}, {
88+
$url: 'http://test.com'
89+
});
90+
91+
assert(typeof command === 'string');
92+
checkXinitrc(format.xinitrcFinalPath, expectedDefault, done);
93+
});
94+
95+
function checkXinitrc(path, expected, done) {
96+
fs.readFile(path, 'utf8', function(err, data) {
5897
if (err) {
5998
throw err;
6099
}
61100
assert.equal(data, expected);
62101
done();
63102
});
64-
});
103+
}
104+
function getTestFormat() {
105+
var format = WebsiteExtension.props.format;
106+
107+
// set test .xinitrc.tpl
108+
format.xinitrcTplPath = __dirname + '/.xinitrc.tpl';
109+
format.xinitrcFinalPath = format.xinitrcTplPath.replace('.tpl', '');
110+
111+
return format;
112+
}
65113
});

0 commit comments

Comments
 (0)