/
yadda-annotations.js
79 lines (66 loc) · 2.33 KB
/
yadda-annotations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import ENV from '../../config/environment';
import { describe } from 'mocha';
import { setupApplicationTest, setupRenderingTest, setupTest } from 'ember-mocha';
// this logic could be anything, but in this case...
// if @ignore, then return skip (for backwards compatibility)
// if have annotations in config, then only run those that have a matching annotation
function checkAnnotations(annotations) {
// if ignore is set then we want to skip for backwards compatibility
if (annotations.ignore) {
return ignoreIt;
}
// if have annotations set in config, the only run those that have a matching annotation
if (ENV.annotations && ENV.annotations.length >= 0) {
for (let annotation in annotations) {
if (ENV.annotations.indexOf(annotation) >= 0) {
// have match, so test it
return 'testIt'; // return something other than a function
}
}
// no match, so don't run it
return logIt;
}
}
// call back functions
function ignoreIt(testElement) {
describe.skip(`${testElement.title}`, () => {});
}
function logIt(testElement) {
console.info(`Not running or skipping: "${testElement.title}"`); // eslint-disable-line no-console
}
// exported functions
function runFeature(annotations) {
return checkAnnotations(annotations);
}
function runScenario(featureAnnotations, scenarioAnnotations) {
return checkAnnotations(scenarioAnnotations);
}
// setup tests
// you can override these function to add additional setup setups, or handle new setup related annotations
function setupFeature(featureAnnotations) {
return setupYaddaTest(featureAnnotations);
}
function setupScenario(featureAnnotations, scenarioAnnotations) {
let setupFn = setupYaddaTest(scenarioAnnotations);
if (setupFn && (featureAnnotations.setupapplicationtest || featureAnnotations.setuprenderingtest || featureAnnotations.setuptest)) {
throw new Error('You must not assign any @setupapplicationtest, @setuprenderingtest or @setuptest annotations to a scenario as well as its feature!');
}
return setupFn;
}
function setupYaddaTest(annotations) {
if (annotations.setupapplicationtest) {
return setupApplicationTest;
}
if (annotations.setuprenderingtest) {
return setupRenderingTest;
}
if (annotations.setuptest) {
return setupTest;
}
}
export {
runFeature,
runScenario,
setupFeature,
setupScenario
};