Skip to content

Commit

Permalink
Tests: Add integration with Istanbul NYC
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Sep 19, 2021
1 parent 83c7052 commit f403a02
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
# https://editorconfig.org

root = true

Expand All @@ -12,6 +11,8 @@ insert_final_newline = true

[test/cli/TapReporter.js]
trim_trailing_whitespace = false
[test/integration/nyc.js]
trim_trailing_whitespace = false

[*.{yml,md}]
indent_style = space
Expand Down
34 changes: 34 additions & 0 deletions test/integration/nyc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const cp = require( "child_process" );
const path = require( "path" );
const DIR = path.join( __dirname, "nyc" );

QUnit.module( "nyc", {
before: () => {
cp.execSync( "npm install --prefer-offline --no-audit", { cwd: DIR, encoding: "utf8" } );
}
} );

QUnit.test( "test", assert => {
const expected = `
TAP version 13
ok 1 add > two numbers
1..1
# pass 1
# skip 0
# todo 0
# fail 0
--------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|-------------------
All files | 85.71 | 100 | 50 | 85.71 |
nyc | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
nyc/src | 75 | 100 | 50 | 75 |
add.js | 100 | 100 | 100 | 100 |
subtract.js | 50 | 100 | 0 | 50 | 2
--------------|---------|----------|---------|---------|-------------------
`.trim();

const actual = cp.execSync( "npm test", { cwd: DIR, encoding: "utf8" } );
assert.pushResult( { result: actual.includes( expected ), actual, expected } );
} );
3 changes: 3 additions & 0 deletions test/integration/nyc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.nyc_output/
/coverage/
/node_modules/
25 changes: 25 additions & 0 deletions test/integration/nyc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# QUnit ♥️ Istanbul

```bash
npm test
```

```
TAP version 13
ok 1 add > two numbers
1..1
# pass 1
# skip 0
# todo 0
# fail 0
--------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|-------------------
All files | 85.71 | 100 | 50 | 85.71 |
nyc | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
nyc/src | 75 | 100 | 50 | 75 |
add.js | 100 | 100 | 100 | 100 |
subtract.js | 50 | 100 | 0 | 50 | 2
--------------|---------|----------|---------|---------|-------------------
```
7 changes: 7 additions & 0 deletions test/integration/nyc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const add = require( "./src/add.js" );
const subtract = require( "./src/subtract.js" );

module.exports = {
add,
subtract
};
21 changes: 21 additions & 0 deletions test/integration/nyc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"private": true,
"devDependencies": {
"nyc": "15.1.0",
"qunit": "file:../../.."
},
"scripts": {
"test": "nyc qunit"
},
"nyc": {
"exclude": [
"test/"
],
"report-dir": "coverage/",
"reporter": [
"text",
"html",
"lcov"
]
}
}
5 changes: 5 additions & 0 deletions test/integration/nyc/src/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function add( a, b ) {
return a + b;
}

module.exports = add;
5 changes: 5 additions & 0 deletions test/integration/nyc/src/subtract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function substract( a, b ) {
return a - b;
}

module.exports = substract;
7 changes: 7 additions & 0 deletions test/integration/nyc/test/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const add = require( "../index.js" ).add;

QUnit.module( "add", () => {
QUnit.test( "two numbers", assert => {
assert.equal( add( 1, 2 ), 3 );
} );
} );

0 comments on commit f403a02

Please sign in to comment.