Skip to content

Commit

Permalink
chore: move tests to __tests__ folders
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Nov 23, 2017
1 parent 3169db2 commit 073924d
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 151 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "mailonline",
"extends": [
"mailonline",
"mailonline/jest"
],
"rules": {
"import/unambiguous": "off",
"import/no-commonjs": "off"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"reporters": [
["./", {"logLevel": "INFO"}]
],
"testRegex": "test\\/.+\\.(test|spec)\\.jsx?$"
"testRegex": "(test|src)\\/.+\\.(test|spec)\\.jsx?$"
},
"dependencies": {
"chalk": "^2.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/LineWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LineWriter {
const list = [];

if (total) {
const formattedBar = formatStatsBar(passed / total, passed + skipped < total);
const formattedBar = formatStatsBar(passed / total, Boolean(failed));

list.push(formattedBar);

Expand Down
6 changes: 3 additions & 3 deletions src/TapReporter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable id-match, class-methods-use-this, no-console */
const path = require('path');
const chalk = require('chalk');
const LoggerTemporal = require('./LoggerTemporal');
const LoggerTemporal = require('./loggers/LoggerTemporal');
const LineWriter = require('./LineWriter');

const STATUS_PASSED = 'passed';
Expand All @@ -13,11 +13,12 @@ const sShouldFail = Symbol('shouldFail');
class TapReporter {
constructor (globalConfig = {}, options = {}) {
const {logLevel = 'INFO'} = options;
const logger = new LoggerTemporal({logLevel});

this.globalConfig = globalConfig;
this.options = options;
this[sShouldFail] = false;
this.writer = new LineWriter(new LoggerTemporal({logLevel}), globalConfig.rootDir);
this.writer = new LineWriter(logger, globalConfig.rootDir);
this.onAssertionResult = this.onAssertionResult.bind(this);

this.lastAggregatedResults = {};
Expand Down Expand Up @@ -64,7 +65,6 @@ class TapReporter {
this.onRunStartOptions = options;

this.writer.start(results.numTotalTestSuites);
this.writer.blank();
}

onTestResult (test, testResult, aggregatedResults) {
Expand Down
File renamed without changes.
104 changes: 101 additions & 3 deletions test/LineWriter.spec.js → src/__tests__/LineWriter.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable max-nested-callbacks */
const chalk = require('chalk');
const Logger = require('../src/Logger');
const LineWriter = require('../src/LineWriter');
const Logger = require('../loggers/Logger');
const LineWriter = require('../LineWriter');

jest.mock('chalk');
jest.mock('../src/Logger');
jest.mock('../loggers/Logger');

const create = (root = '/jest-tap-reporter', logger = new Logger()) => {
const writer = new LineWriter(logger, root);
Expand Down Expand Up @@ -488,4 +488,102 @@ describe('LineWriter', () => {
});
});
});

describe('.aggregatedResults()', () => {
test('all suites and tests pass', () => {
const writer = create();
const aggregatedResults = {
numFailedTests: 0,
numFailedTestSuites: 0,
numPassedTests: 10,
numPassedTestSuites: 2,
numPendingTests: 0,
numPendingTestSuites: 0,
numTotalTests: 10,
numTotalTestSuites: 2,
snapshot: {},
startTime: Date.now() - 2000
};

writer.stats = jest.fn();
writer.aggregatedResults(aggregatedResults, 1);

expect(writer.stats.mock.calls).toEqual([
['Test Suites', 0, 0, 2, 2],
['Tests', 0, 0, 10, 10]
]);
});

test('some suites and tests fail', () => {
const writer = create();
const aggregatedResults = {
numFailedTests: 1,
numFailedTestSuites: 1,
numPassedTests: 10,
numPassedTestSuites: 2,
numPendingTests: 0,
numPendingTestSuites: 0,
numTotalTests: 10,
numTotalTestSuites: 2,
snapshot: {},
startTime: Date.now() - 2000
};

writer.stats = jest.fn();
writer.aggregatedResults(aggregatedResults, 1);

expect(writer.stats.mock.calls).toEqual([
['Test Suites', 1, 0, 2, 2],
['Tests', 1, 0, 10, 10]
]);
});

test('1 suite failed to execute', () => {
const writer = create();
const aggregatedResults = {
numFailedTests: 0,
numFailedTestSuites: 1,
numPassedTests: 10,
numPassedTestSuites: 1,
numPendingTests: 0,
numPendingTestSuites: 0,
numTotalTests: 10,
numTotalTestSuites: 2,
snapshot: {},
startTime: Date.now() - 2000
};

writer.stats = jest.fn();
writer.aggregatedResults(aggregatedResults, 1);

expect(writer.stats.mock.calls).toEqual([
['Test Suites', 1, 0, 1, 2],
['Tests', 0, 0, 10, 10]
]);
});

test('some suites and tests skipped', () => {
const writer = create();
const aggregatedResults = {
numFailedTests: 0,
numFailedTestSuites: 0,
numPassedTests: 5,
numPassedTestSuites: 1,
numPendingTests: 5,
numPendingTestSuites: 1,
numTotalTests: 10,
numTotalTestSuites: 2,
snapshot: {},
startTime: Date.now() - 2000
};

writer.stats = jest.fn();
writer.aggregatedResults(aggregatedResults, 1);

expect(writer.stats.mock.calls).toEqual([
['Test Suites', 0, 1, 1, 2],
['Tests', 0, 5, 5, 10]
]);
});
});
});
119 changes: 23 additions & 96 deletions test/TapReporter.spec.js → src/__tests__/TapReporter.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
/* eslint-disable no-console, max-nested-callbacks */
const chalk = require('chalk');
const TapReporter = require('../src/TapReporter');
const TapReporter = require('../TapReporter');
const LoggerTemporal = require('../loggers/LoggerTemporal');
const {
failingTestSuite,
passingTestSuite,
severalTestsSuite,
skippedTestSuite
} = require('./fixtures');
} = require('../../test/fixtures');

jest.mock('chalk');
jest.mock('../src/LineWriter');
jest.mock('../LineWriter');
jest.mock('../loggers/LoggerTemporal');

const newTapReporter = () => {
const tapReporter = new TapReporter();

tapReporter.writer.logger = new LoggerTemporal();

return tapReporter;
};

describe('TapReporter', () => {
test('must publish the globalConfig and the options', () => {
Expand Down Expand Up @@ -55,7 +65,7 @@ describe('TapReporter', () => {
describe('onTestResults', () => {
test('must output error tests', () => {
chalk.__stripColors();
const tapReporter = new TapReporter();
const tapReporter = newTapReporter();

tapReporter.onTestResult({}, failingTestSuite);

Expand All @@ -65,7 +75,7 @@ describe('TapReporter', () => {

test('must output passing tests', () => {
chalk.__stripColors();
const tapReporter = new TapReporter();
const tapReporter = newTapReporter();

tapReporter.onTestResult({}, passingTestSuite);

Expand All @@ -75,7 +85,7 @@ describe('TapReporter', () => {

test('must output skipped tests', () => {
chalk.__stripColors();
const tapReporter = new TapReporter();
const tapReporter = newTapReporter();

tapReporter.onTestResult({}, skippedTestSuite);

Expand All @@ -85,7 +95,7 @@ describe('TapReporter', () => {

test('must output all the tests on a suite tests', () => {
chalk.__stripColors();
const tapReporter = new TapReporter();
const tapReporter = newTapReporter();

tapReporter.onTestResult({}, severalTestsSuite);

Expand All @@ -96,7 +106,7 @@ describe('TapReporter', () => {

describe('suite log', () => {
test('must output a suite log with the Suites filePath if possible', () => {
const tapReporter = new TapReporter();
const tapReporter = newTapReporter();

tapReporter.onTestResult({}, passingTestSuite);

Expand All @@ -107,96 +117,13 @@ describe('TapReporter', () => {
});

describe('onRunComplete', () => {
test('all suites and tests pass', () => {
const tapReporter = new TapReporter();
const results = {
numFailedTests: 0,
numFailedTestSuites: 0,
numPassedTests: 10,
numPassedTestSuites: 2,
numPendingTests: 0,
numPendingTestSuites: 0,
numTotalTests: 10,
numTotalTestSuites: 2,
snapshot: {},
startTime: Date.now() - 2000
};

tapReporter.onRunComplete({}, results);

expect(tapReporter.writer.stats.mock.calls).toEqual([
['Test Suites', 0, 0, 2, 2],
['Tests', 0, 0, 10, 10]
]);
});
test('calls .aggregatedResults() printer', () => {
const tapReporter = newTapReporter();
const aggregatedResults = {};

test('some suites and tests fail', () => {
const tapReporter = new TapReporter();
const results = {
numFailedTests: 1,
numFailedTestSuites: 1,
numPassedTests: 10,
numPassedTestSuites: 2,
numPendingTests: 0,
numPendingTestSuites: 0,
numTotalTests: 10,
numTotalTestSuites: 2,
snapshot: {},
startTime: Date.now() - 2000
};

tapReporter.onRunComplete({}, results);

expect(tapReporter.writer.stats.mock.calls).toEqual([
['Test Suites', 1, 0, 2, 2],
['Tests', 1, 0, 10, 10]
]);
});

test('1 suite failed to execute', () => {
const tapReporter = new TapReporter();
const results = {
numFailedTests: 0,
numFailedTestSuites: 1,
numPassedTests: 10,
numPassedTestSuites: 1,
numPendingTests: 0,
numPendingTestSuites: 0,
numTotalTests: 10,
numTotalTestSuites: 2,
snapshot: {},
startTime: Date.now() - 2000
};

tapReporter.onRunComplete({}, results);

expect(tapReporter.writer.stats.mock.calls).toEqual([
['Test Suites', 1, 0, 1, 2],
['Tests', 0, 0, 10, 10]
]);
});
tapReporter.onRunComplete({}, aggregatedResults);

test('some suites and tests skipped', () => {
const tapReporter = new TapReporter();
const results = {
numFailedTests: 0,
numFailedTestSuites: 0,
numPassedTests: 5,
numPassedTestSuites: 1,
numPendingTests: 5,
numPendingTestSuites: 1,
numTotalTests: 10,
numTotalTestSuites: 2,
snapshot: {},
startTime: Date.now() - 2000
};

tapReporter.onRunComplete({}, results);

expect(tapReporter.writer.stats.mock.calls).toEqual([
['Test Suites', 0, 1, 1, 2],
['Tests', 0, 5, 5, 10]
]);
expect(tapReporter.writer.aggregatedResults.mock.calls[0][0]).toBe(aggregatedResults);
});
});
});
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const index = require('../../index');
const TapReport = require('../TapReporter');

test('index must export TapReport', () => {
expect(index).toBe(TapReport);
});
2 changes: 1 addition & 1 deletion src/Logger.js → src/loggers/Logger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const formatLog = require('./format/formatLog');
const formatLog = require('../format/formatLog');

/* eslint-disable sort-keys */
const LEVELS = {
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 073924d

Please sign in to comment.