Skip to content

Commit 40b0496

Browse files
Merge pull request #7 from NativeScript/add-e2e-tests
Add Mocha e2e tests
2 parents bd6d45c + a137c98 commit 40b0496

File tree

10 files changed

+76
-8
lines changed

10 files changed

+76
-8
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#JavaScript
22
*.tgz
33
*.js
4-
!tests/*.js
4+
!prepare-tests.js
5+
!test/*.js
56
*.js.map
67

78
#Node
@@ -11,4 +12,4 @@ node_modules/
1112
#OSX
1213
.DS_Store
1314

14-
tests/docsroot-output/
15+
test/docsroot-output/

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
tags
44
tsconfig.json
55

6-
tests/
6+
test/

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,12 @@ When injected, a snippet is formatted using the default MarkDown code-snippet fo
162162
```
163163
mdinject --root=. --docsroot=../ --sourceext=".java|.cs" --targetext=".md|.txt" --snippettitles="Java|C#"
164164
```
165+
166+
## Run e2e tests
167+
1. Clone repo
168+
2. npm install
169+
3. npm test
170+
171+
E2E tests are developed with [Mocha](https://mochajs.org).
172+
165173
> Note that the order of the snippet titles must be the related to the order of the source extension types so that they match.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"definition": "index.d.ts"
1212
},
1313
"scripts": {
14-
"prepublish": "tsc -p ."
14+
"prepublish": "tsc -p .",
15+
"test": "mocha"
1516
},
1617
"keywords": [
1718
"markdown",
@@ -22,10 +23,11 @@
2223
"author": "Deyan Ginev",
2324
"license": "MIT",
2425
"dependencies": {
25-
"yargs": "^4.1.0",
26-
"typescript": "^1.7.5"
26+
"typescript": "^1.7.5",
27+
"yargs": "^4.1.0"
2728
},
2829
"devDependencies": {
30+
"mocha": "^3.2.0",
2931
"shelljs": "^0.6.0"
3032
}
3133
}

tests/prepare-tests.js renamed to prepare-tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ var shelljs = require("shelljs");
44

55
shelljs.echo('Preparing for tests ...');
66

7-
shelljs.rm('-rf', 'tests/docsroot-output');
7+
shelljs.rm('-rf', 'test/docsroot-output');
88

9-
shelljs.cp("-R", "tests/docsroot", "tests/docsroot-output");
9+
shelljs.cp("-R", "test/docsroot", "test/docsroot-output");
1010

1111
shelljs.echo('Preparing for tests ... DONE');
1212

File renamed without changes.

test/e2e.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var assert = require('assert'),
2+
fs = require('fs'),
3+
shelljs = require("shelljs"),
4+
rootFolder = "test/root",
5+
docsrootFolder = "./test/docsroot-output";
6+
7+
function preparedemo() {
8+
console.log('Preparing for tests ...');
9+
shelljs.rm('-rf', docsrootFolder);
10+
shelljs.cp("-R", "test/docsroot", docsrootFolder);
11+
console.log('Preparing for tests ... DONE');
12+
}
13+
14+
function hasPattern(pattern, shouldExists, callback) {
15+
fs.readFile(docsrootFolder + '/test.md', function read(err, data) {
16+
if (err) {
17+
callback('Pattern ' + pattern + ' is NOT found because of an error: ' + err);
18+
} else {
19+
if (data.toString().indexOf(pattern) === -1) {
20+
callback(shouldExists ? 'Pattern ' + pattern + ' is NOT found' : null);
21+
} else {
22+
callback(shouldExists ? null : 'Pattern ' + pattern + ' WAS found. This is NOT expected.');
23+
}
24+
25+
}
26+
});
27+
}
28+
29+
describe('markdown-snippet-injector', function () {
30+
31+
beforeEach(function (done) {
32+
preparedemo();
33+
done();
34+
});
35+
36+
//TODO: Add tests for hidden fields
37+
38+
it('should process XML snippets', function (done) {
39+
shelljs.exec('node index.js --root=./test/root --docsroot=./test/docsroot-output --sourceext=".xml"');
40+
hasPattern("<snippet id='xml-snippet'/>", false, done);
41+
});
42+
43+
it('should process TypeScript snippets', function (done) {
44+
shelljs.exec('node index.js --root=./test/root --docsroot=./test/docsroot-output --sourceext=".ts"');
45+
hasPattern("<snippet id='ts-snippet'/>", false, done);
46+
});
47+
48+
it('should process CSS snippets', function (done) {
49+
shelljs.exec('node index.js --root=./test/root --docsroot=./test/docsroot-output --sourceext=".css"');
50+
hasPattern("<snippet id='css-snippet'/>", false, done);
51+
});
52+
53+
it('should NOT process snippetIds that are not defined in source', function (done) {
54+
shelljs.exec('node index.js --root=./test/root --docsroot=./test/docsroot-output --sourceext=".css"');
55+
hasPattern("<snippet id='cssSnippet'/>", true, done);
56+
});
57+
});
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)