Skip to content

Commit c9a4eb5

Browse files
committed
try new syntax tests
1 parent 094e06d commit c9a4eb5

File tree

3 files changed

+68
-25
lines changed

3 files changed

+68
-25
lines changed

tasks/shard_jasmine_tests.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var falafel = require('falafel');
55
var glob = require('glob');
66
var minimist = require('minimist');
77

8-
var constants = require('./util/constants');
9-
var pathToJasmineTests = constants.pathToJasmineTests;
8+
var pathToJasmineTests = require('./util/constants').pathToJasmineTests;
9+
var isJasmineTestIt = require('./util/common').isJasmineTestIt;
1010

1111
var argv = minimist(process.argv.slice(2), {
1212
string: ['tag', 'limit'],
@@ -32,7 +32,7 @@ glob(path.join(pathToJasmineTests, '*.js'), function(err, files) {
3232
var bn = path.basename(file);
3333

3434
falafel(code, function(node) {
35-
if(isTestDescription(node, tag)) {
35+
if(isJasmineTestIt(node, tag)) {
3636
if(file2cnt[bn]) {
3737
file2cnt[bn]++;
3838
} else {
@@ -92,21 +92,3 @@ glob(path.join(pathToJasmineTests, '*.js'), function(err, files) {
9292
// print result to stdout
9393
console.log(runs.join('\n'));
9494
});
95-
96-
function isTestDescription(node, tag) {
97-
var isDescription = (
98-
node.type === 'Literal' &&
99-
node.parent &&
100-
node.parent.type === 'CallExpression' &&
101-
node.parent.callee &&
102-
node.parent.callee.type === 'Identifier' &&
103-
node.parent.callee.name === 'it'
104-
);
105-
106-
if(!tag) return isDescription;
107-
108-
return (
109-
isDescription &&
110-
node.source().indexOf('@' + tag) !== -1
111-
);
112-
}

tasks/test_syntax.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ var readLastLines = require('read-last-lines');
88
var eslint = require('eslint');
99
var trueCasePath = require('true-case-path');
1010

11+
var common = require('./util/common');
12+
var isJasmineTestIt = common.isJasmineTestIt;
13+
var isJasmineTestDescribe = common.isJasmineTestDescribe;
14+
var hasJasmineTestTag = common.hasJasmineTestTag;
15+
1116
var constants = require('./util/constants');
1217
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
1318
var libGlob = path.join(constants.pathToLib, '**/*.js');
@@ -28,26 +33,55 @@ assertES5();
2833
// check for for focus and exclude jasmine blocks
2934
function assertJasmineSuites() {
3035
var BLACK_LIST = ['fdescribe', 'fit', 'xdescribe', 'xit'];
36+
var TAGS = ['noCI', 'noCIdep', 'gl', 'flaky'];
3137
var logs = [];
3238

3339
glob(combineGlobs([testGlob, bundleTestGlob]), function(err, files) {
3440
files.forEach(function(file) {
3541
var code = fs.readFileSync(file, 'utf-8');
42+
var bn = path.basename(file);
3643

3744
falafel(code, {locations: true}, function(node) {
45+
var lineInfo = '[line ' + node.loc.start.line + '] :';
46+
3847
if(node.type === 'Identifier' && BLACK_LIST.indexOf(node.name) !== -1) {
3948
logs.push([
40-
path.basename(file),
41-
'[line ' + node.loc.start.line + '] :',
49+
bn, lineInfo,
4250
'contains either a *fdescribe*, *fit*,',
4351
'*xdescribe* or *xit* block.'
4452
].join(' '));
4553
}
46-
});
4754

55+
if(isJasmineTestIt(node)) {
56+
if(hasJasmineTestTag(node)) {
57+
if(TAGS.every(function(t) { return !hasJasmineTestTag(node, t); })) {
58+
logs.push([
59+
bn, lineInfo,
60+
'contains an unrecognized tag,',
61+
'not one of: ' + TAGS.map(function(t) { return '\@' + t; }).join(', ')
62+
].join(' '));
63+
}
64+
}
65+
66+
if(hasJasmineTestTag(node, 'gl') && hasJasmineTestTag(node, 'flaky')) {
67+
logs.push([
68+
bn, lineInfo,
69+
'contains a @gl tag AND a @flaky tag, which is not allowed'
70+
].join(' '));
71+
}
72+
}
73+
74+
if(isJasmineTestDescribe(node, 'gl')) {
75+
logs.push([
76+
bn, lineInfo,
77+
'contains a @gl tag is a *describe* block,',
78+
'@gl tags are allowed only in jasmine *it* blocks.'
79+
].join(' '));
80+
}
81+
});
4882
});
4983

50-
log('no jasmine suites focus/exclude blocks', logs);
84+
log('no jasmine suites focus/exclude blocks or wrong tag patterns', logs);
5185
});
5286
}
5387

tasks/util/common.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,30 @@ exports.formatEnumeration = function(list) {
105105
return '`' + l + '`' + ending;
106106
}).join(' ');
107107
};
108+
109+
exports.hasJasmineTestTag = function(node, tag) {
110+
var re = tag ?
111+
new RegExp('@' + tag + '\\s') :
112+
new RegExp('@' + '\\w');
113+
return re.test(node.source());
114+
};
115+
116+
function isJasmineBase(block, node, tag) {
117+
return (
118+
node.type === 'Literal' &&
119+
node.parent &&
120+
node.parent.type === 'CallExpression' &&
121+
node.parent.callee &&
122+
node.parent.callee.type === 'Identifier' &&
123+
node.parent.callee.name === block &&
124+
(tag === undefined || exports.hasJasmineTestTag(node, tag))
125+
);
126+
}
127+
128+
exports.isJasmineTestIt = function(node, tag) {
129+
return isJasmineBase('it', node, tag);
130+
};
131+
132+
exports.isJasmineTestDescribe = function(node, tag) {
133+
return isJasmineBase('describe', node, tag);
134+
};

0 commit comments

Comments
 (0)