Skip to content

Commit

Permalink
Merge pull request #439 from choheekim/update-readme
Browse files Browse the repository at this point in the history
Update README reflecting to current changes in module-metadata-file
  • Loading branch information
choheekim authored Dec 5, 2019
2 parents 417f7e0 + 040299d commit b8efb9f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 16 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ It creates a json file, `module-metadata-<timestamp>.json`, which contains an ar
```json
[
{
"name": "Module-name",
"moduleName": "Module-name",
"total": "Total number of tests in the module",
"duration": "ms in Total duration to execute the module"
"passed": "A number of passed tests in the module",
"failed": "A number of failed tests in the module",
"skipped": "A number of skipped tests in the module",
"duration": "ms in Total duration to execute the module",
"failedTests": "A list of failed tests"
}
]
```
Expand All @@ -164,14 +168,22 @@ and it looks something like below:
```json
[
{
"name": "Slowest Module",
"moduleName": "Slowest-module",
"total": 12,
"duration": 2159
"passed": 9,
"failed": 1,
"skipped": 2,
"duration": 153,
"failedTests": ["failed-test-1"]
},
{
"name": "Fastest Module",
"total": 9,
"duration": 125
"moduleName": "Fastest-module",
"total": 2,
"passed": 1,
"failed": 0,
"skipped": 0,
"duration": 123,
"failedTests": []
}
]
```
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/exam.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ module.exports = TestCommand.extend({
{
moduleName: details.module,
testName: details.name,
passed: details.passed == details.total,
failed: (details.failed > 0),
skipped: details.skipped,
duration: details.runtime
}
)
Expand Down
13 changes: 8 additions & 5 deletions lib/utils/execution-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,15 @@ class ExecutionStateManager {
* @param {number} duration - duration to execute tests in module in ms
* @param {Array<string>} failedTests - A list of failed test names
*/
_injectModuleMetadata(moduleName, total, passed, failed, duration, failedTests) {
_injectModuleMetadata(moduleName, total, passed, failed, skipped, duration, failedTests) {
this._moduleMetadata.set(
moduleName,
{
moduleName,
total,
passed,
failed,
skipped,
duration,
failedTests
}
Expand All @@ -209,20 +210,22 @@ class ExecutionStateManager {
*/
addToModuleMetadata(metadata) {
if (!this._moduleMetadata.has(metadata.moduleName)) {
this._injectModuleMetadata(metadata.moduleName, 0, 0, 0, 0, []);
// modulename, total, passed, failed, skipped, duration, failed tests
this._injectModuleMetadata(metadata.moduleName, 0, 0, 0, 0, 0, []);
}

const curModuleMetadata = this._moduleMetadata.get(metadata.moduleName);

if (metadata.failed) {
if (!metadata.skipped && metadata.failed) {
curModuleMetadata.failedTests.push(metadata.testName);
}

this._injectModuleMetadata(
metadata.moduleName,
curModuleMetadata.total + 1,
( metadata.failed ? curModuleMetadata.passed : curModuleMetadata.passed + 1),
( metadata.failed ? curModuleMetadata.failed + 1 : curModuleMetadata.failed),
( !metadata.skipped && metadata.passed ? curModuleMetadata.passed + 1 : curModuleMetadata.passed ),
( !metadata.skipped && metadata.failed ? curModuleMetadata.failed + 1 : curModuleMetadata.failed ),
( metadata.skipped ? curModuleMetadata.skipped + 1 : curModuleMetadata.skipped ),
curModuleMetadata.duration + metadata.duration,
curModuleMetadata.failedTests
);
Expand Down
17 changes: 17 additions & 0 deletions node-tests/unit/utils/execution-state-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ describe('ExecutionStateManager', function() {
const moduleMetadata = {
moduleName: testModuleName,
testName: 'testing foo',
passed: 1,
failed: 0,
skipped: false,
total: 1,
duration: 1
};

Expand All @@ -130,6 +133,10 @@ describe('ExecutionStateManager', function() {
fooModuleMetadata.failed,
0
);
assert.equal(
fooModuleMetadata.skipped,
0
);
assert.equal(
fooModuleMetadata.duration,
1
Expand All @@ -145,14 +152,20 @@ describe('ExecutionStateManager', function() {
const fooTestMetadata = {
moduleName: fooTestModule,
testName: 'testing foo',
passed: 1,
failed: 0,
skipped: false,
total: 1,
duration: 1
};

const barTestMetadata = {
moduleName: fooTestModule,
testName: 'testing bar',
passed: 0,
failed: 1,
skipped: false,
total: 1,
duration: 1.8
};

Expand All @@ -175,6 +188,10 @@ describe('ExecutionStateManager', function() {
fooModuleMetadata.failed,
1
);
assert.equal(
fooModuleMetadata.skipped,
0
);
assert.equal(
fooModuleMetadata.duration,
2.8
Expand Down
54 changes: 50 additions & 4 deletions node-tests/unit/utils/testem-events-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('TestemEvents', function() {
});

it('should write module-run-details file and cleanup state when completedBrowsers equals browserCount, load-balance is true, and write-execution-file is false', function() {
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'a', testName: 'test', failed: false, duration: 1});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'a', testName: 'test', passed: true, failed: false, skipped: false, duration: 1});
this.testemEvents.completedBrowsersHandler(
1,
1,
Expand All @@ -245,16 +245,17 @@ describe('TestemEvents', function() {
total: 1,
passed: 1,
failed: 0,
skipped: 0,
duration: 1,
failedTests: []
}
]);
});

it('should write module-run-details file with sorted by duration', function() {
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'a', testName: 'test 1', failed: false, duration: 1});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'a', testName: 'test 2', failed: true, duration: 8});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'b', testName: 'test 1', failed: false, duration: 1});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'a', testName: 'test 1', passed: true, failed: false, skipped: false, duration: 1});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'a', testName: 'test 2', passed: false, failed: true, skipped: false, duration: 8});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'b', testName: 'test 1', passed: true, failed: false, skipped: false, duration: 1});


this.testemEvents.completedBrowsersHandler(
Expand All @@ -278,6 +279,7 @@ describe('TestemEvents', function() {
total: 2,
passed: 1,
failed: 1,
skipped: 0,
duration: 9,
failedTests: ['test 2']
},
Expand All @@ -286,12 +288,56 @@ describe('TestemEvents', function() {
total: 1,
passed: 1,
failed: 0,
skipped: 0,
duration: 1,
failedTests: []
}
]);
});

it('should add skipped test number to write module-run-details file with sorted by duration', function() {
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'a', testName: 'test 1', passed: true, failed: false, skipped: true, duration: 0});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'a', testName: 'test 2', passed: false, failed: true, skipped: false, duration: 8});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'b', testName: 'test 1', passed: true, failed: false, skipped: false, duration: 1});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'b', testName: 'test 1', passed: true, failed: false, skipped: false, duration: 0});
this.testemEvents.stateManager.addToModuleMetadata({ moduleName: 'b', testName: 'test 1', paseed: true, failed: false, skipped: true, duration: 1});

this.testemEvents.completedBrowsersHandler(
1,
1,
mockUi,
new Map([
['loadBalance', true],
['writeModuleMetadataFile', true]
]),
'0000'
);

const actual = fs.readFileSync(
path.join(fixtureDir, 'module-metadata-0000.json')
);

assert.deepEqual(JSON.parse(actual), [
{
moduleName: 'a',
total: 2,
passed: 0,
failed: 1,
skipped: 1,
duration: 8,
failedTests: ['test 2']
},
{
moduleName: 'b',
total: 3,
passed: 2,
failed: 0,
skipped: 1,
duration: 2,
failedTests: []
}
]);
});

it('should increment completedBrowsers when load-balance is false', function() {
this.testemEvents.completedBrowsersHandler(
Expand Down

0 comments on commit b8efb9f

Please sign in to comment.