Skip to content

Commit

Permalink
update tests by removing call to createSandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
sharath2106 committed Jun 27, 2020
1 parent a1d3984 commit 181a20b
Show file tree
Hide file tree
Showing 22 changed files with 320 additions and 416 deletions.
18 changes: 8 additions & 10 deletions test/node-unit/buffered-runner.spec.js
Expand Up @@ -13,11 +13,10 @@ const BUFFERED_RUNNER_PATH = require.resolve(
);
const Suite = require('../../lib/suite');
const Runner = require('../../lib/runner');
const {createSandbox} = require('sinon');
const sinon = require('sinon');

describe('buffered-runner', function() {
describe('BufferedRunner', function() {
let sandbox;
let run;
let BufferedWorkerPool;
let terminate;
Expand All @@ -27,27 +26,26 @@ describe('buffered-runner', function() {
let cpuCount;

beforeEach(function() {
sandbox = createSandbox();
cpuCount = 1;
suite = new Suite('a root suite', {}, true);
warn = sandbox.stub();
warn = sinon.stub();

// tests will want to further define the behavior of these.
run = sandbox.stub();
terminate = sandbox.stub();
run = sinon.stub();
terminate = sinon.stub();
BufferedWorkerPool = {
create: sandbox.stub().returns({
create: sinon.stub().returns({
run,
terminate,
stats: sandbox.stub().returns({})
stats: sinon.stub().returns({})
})
};
BufferedRunner = rewiremock.proxy(BUFFERED_RUNNER_PATH, r => ({
'../../lib/nodejs/buffered-worker-pool': {
BufferedWorkerPool
},
os: {
cpus: sandbox.stub().callsFake(() => new Array(cpuCount))
cpus: sinon.stub().callsFake(() => new Array(cpuCount))
},
'../../lib/utils': r.with({warn}).callThrough()
}));
Expand Down Expand Up @@ -157,7 +155,7 @@ describe('buffered-runner', function() {

it('should delegate to Runner#uncaught', function(done) {
const options = {};
sandbox.spy(runner, 'uncaught');
sinon.spy(runner, 'uncaught');
const err = new Error('whoops');
run.withArgs('some-file.js', options).rejects(new Error('whoops'));
run.withArgs('some-other-file.js', options).resolves({
Expand Down
18 changes: 8 additions & 10 deletions test/node-unit/buffered-worker-pool.spec.js
@@ -1,36 +1,34 @@
'use strict';

const rewiremock = require('rewiremock/node');
const {createSandbox} = require('sinon');
const sinon = require('sinon');

describe('class BufferedWorkerPool', function() {
let BufferedWorkerPool;
let sandbox;
let pool;
let stats;
let serializeJavascript;
let serializer;
let result;

beforeEach(function() {
sandbox = createSandbox();
stats = {totalWorkers: 10, busyWorkers: 8, idleWorkers: 2, pendingTasks: 3};
result = {failures: 0, events: []};
pool = {
terminate: sandbox.stub().resolves(),
exec: sandbox.stub().resolves(result),
stats: sandbox.stub().returns(stats)
terminate: sinon.stub().resolves(),
exec: sinon.stub().resolves(result),
stats: sinon.stub().returns(stats)
};
serializer = {
deserialize: sandbox.stub()
deserialize: sinon.stub()
};

serializeJavascript = sandbox.spy(require('serialize-javascript'));
serializeJavascript = sinon.spy(require('serialize-javascript'));
BufferedWorkerPool = rewiremock.proxy(
require.resolve('../../lib/nodejs/buffered-worker-pool'),
{
workerpool: {
pool: sandbox.stub().returns(pool),
pool: sinon.stub().returns(pool),
cpus: 8
},
'../../lib/nodejs/serializer': serializer,
Expand All @@ -43,7 +41,7 @@ describe('class BufferedWorkerPool', function() {
});

afterEach(function() {
sandbox.restore();
sinon.restore();
});

describe('static method', function() {
Expand Down
21 changes: 8 additions & 13 deletions test/node-unit/cli/config.spec.js
@@ -1,18 +1,13 @@
'use strict';

const {createSandbox} = require('sinon');
const sinon = require('sinon');
const rewiremock = require('rewiremock/node');

describe('cli/config', function() {
let sandbox;
const phonyConfigObject = {ok: true};

beforeEach(function() {
sandbox = createSandbox();
});

afterEach(function() {
sandbox.restore();
sinon.restore();
});

describe('loadConfig()', function() {
Expand All @@ -29,9 +24,9 @@ describe('cli/config', function() {

describe('when parsing succeeds', function() {
beforeEach(function() {
sandbox.stub(parsers, 'yaml').returns(phonyConfigObject);
sandbox.stub(parsers, 'json').returns(phonyConfigObject);
sandbox.stub(parsers, 'js').returns(phonyConfigObject);
sinon.stub(parsers, 'yaml').returns(phonyConfigObject);
sinon.stub(parsers, 'json').returns(phonyConfigObject);
sinon.stub(parsers, 'js').returns(phonyConfigObject);
});

describe('when supplied a filepath with ".yaml" extension', function() {
Expand Down Expand Up @@ -103,7 +98,7 @@ describe('cli/config', function() {

describe('when supplied a filepath with unsupported extension', function() {
beforeEach(function() {
sandbox.stub(parsers, 'json').returns(phonyConfigObject);
sinon.stub(parsers, 'json').returns(phonyConfigObject);
});

it('should use the JSON parser', function() {
Expand All @@ -114,7 +109,7 @@ describe('cli/config', function() {

describe('when config file parsing fails', function() {
beforeEach(function() {
sandbox.stub(parsers, 'yaml').throws();
sinon.stub(parsers, 'yaml').throws();
});

it('should throw', function() {
Expand All @@ -129,7 +124,7 @@ describe('cli/config', function() {
let CONFIG_FILES;

beforeEach(function() {
findup = {sync: sandbox.stub().returns('/some/path/.mocharc.js')};
findup = {sync: sinon.stub().returns('/some/path/.mocharc.js')};
const config = rewiremock.proxy(
require.resolve('../../../lib/cli/config'),
r => ({
Expand Down

0 comments on commit 181a20b

Please sign in to comment.