Skip to content

Commit

Permalink
[cli] use sinon default sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed May 16, 2018
1 parent 45c0408 commit 4a7ae2f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 42 deletions.
11 changes: 3 additions & 8 deletions packages/cli/src/test/unit/commands/init_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@ import * as polymerInit from '../../../init/init';
import {PolymerCli} from '../../../polymer-cli';

suite('init', () => {
let sandbox: sinon.SinonSandbox;

setup(() => {
sandbox = sinon.sandbox.create();
});

teardown(() => {
sandbox.restore();
sinon.restore();
});

test('runs the given generator when name argument is provided', async () => {
const runGeneratorStub =
sandbox.stub(polymerInit, 'runGenerator').returns(Promise.resolve());
sinon.stub(polymerInit, 'runGenerator').returns(Promise.resolve());
const cli = new PolymerCli(['init', 'shop']);
await cli.run();
assert.isOk(runGeneratorStub.calledOnce);
Expand All @@ -41,7 +36,7 @@ suite('init', () => {
'prompts the user to select a generator when no argument is provided';
test(testName, async () => {
const promptSelectionStub =
sandbox.stub(polymerInit, 'promptGeneratorSelection')
sinon.stub(polymerInit, 'promptGeneratorSelection')
.returns(Promise.resolve());
const cli = new PolymerCli(['init']);
await cli.run();
Expand Down
9 changes: 3 additions & 6 deletions packages/cli/src/test/unit/commands/serve_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,26 @@ suite('serve', () => {

suite('--npm and --component-dir', () => {

let sandbox: sinon.SinonSandbox;
let startServersStub: sinon.SinonStub;
let getServerUrlsStub: sinon.SinonStub;

setup(() => {
sandbox = sinon.sandbox.create();

startServersStub =
sandbox.stub(polyserve, 'startServers').returns(Promise.resolve());
sinon.stub(polyserve, 'startServers').returns(Promise.resolve());
startServersStub.returns({
kind: 'mainline',
});

getServerUrlsStub =
sandbox.stub(polyserve, 'getServerUrls').returns(Promise.resolve());
sinon.stub(polyserve, 'getServerUrls').returns(Promise.resolve());
getServerUrlsStub.returns({
serverUrl: 'http://applications.example.com/',
componentUrl: 'http://components.example.com/',
});
});

teardown(() => {
sandbox.restore();
sinon.restore();
});

test(
Expand Down
16 changes: 5 additions & 11 deletions packages/cli/src/test/unit/commands/test_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@ import * as wct from 'web-component-tester';
import {PolymerCli} from '../../../polymer-cli';

suite('test', () => {
let sandbox: sinon.SinonSandbox;

setup(() => {
sandbox = sinon.sandbox.create();
});

teardown(() => {
sandbox.restore();
sinon.restore();
});

test(
'--npm flag is passed to WCT and sets the --component-dir flag',
async () => {
const wctCliRunStub =
sandbox.stub(wct.cli, 'run').returns(Promise.resolve());
sinon.stub(wct.cli, 'run').returns(Promise.resolve());
const cli = new PolymerCli(['test', '--npm']);
await cli.run();

Expand All @@ -43,7 +37,7 @@ suite('test', () => {
'--npm flag',
async () => {
const wctCliRunStub =
sandbox.stub(wct.cli, 'run').returns(Promise.resolve());
sinon.stub(wct.cli, 'run').returns(Promise.resolve());
const cli =
new PolymerCli(['test', '--npm', '--component-dir=path/to/deps/']);
await cli.run();
Expand All @@ -55,7 +49,7 @@ suite('test', () => {

test('--component-dir flag is passed to WCT', async () => {
const wctCliRunStub =
sandbox.stub(wct.cli, 'run').returns(Promise.resolve());
sinon.stub(wct.cli, 'run').returns(Promise.resolve());
const cli = new PolymerCli(['test', '--component-dir=path/to/deps/']);
await cli.run();

Expand All @@ -66,7 +60,7 @@ suite('test', () => {

test('--module-resolution flag is passed to WCT', async () => {
const wctCliRunStub =
sandbox.stub(wct.cli, 'run').returns(Promise.resolve());
sinon.stub(wct.cli, 'run').returns(Promise.resolve());
const cli = new PolymerCli(['test', '--module-resolution=none']);
await cli.run();

Expand Down
28 changes: 11 additions & 17 deletions packages/cli/src/test/unit/init/init_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@ interface FakeEnv {
}

suite('init', () => {
let sandbox: sinon.SinonSandbox;

function createFakeEnv(): FakeEnv {
return {
getGeneratorsMeta: sandbox.stub(),
run: sandbox.stub().yields(),
getGeneratorsMeta: sinon.stub(),
run: sinon.stub().yields(),
};
}

setup(() => {
sandbox = sinon.sandbox.create();
});

teardown(() => {
sandbox.restore();
sinon.restore();
});

suite('runGenerator', () => {
Expand Down Expand Up @@ -179,7 +173,7 @@ suite('init', () => {


test('works with the default yeoman environment', async () => {
sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({
sinon.stub(inquirer, 'prompt').returns(Promise.resolve({
foo: 'TEST',
}));
// tslint:disable-next-line: no-any
Expand All @@ -191,7 +185,7 @@ suite('init', () => {
let testName =
'prompts with a list to get generatorName property from user';
test(testName, async () => {
const promptStub = sandbox.stub(inquirer, 'prompt')
const promptStub = sinon.stub(inquirer, 'prompt')
.returns(Promise.resolve({foo: 'TEST'}));
try {
await polymerInit.promptGeneratorSelection({env: yeomanEnvMock});
Expand All @@ -206,7 +200,7 @@ suite('init', () => {
});

test('prompts with a list of all registered generators', async () => {
const promptStub = sandbox.stub(inquirer, 'prompt')
const promptStub = sinon.stub(inquirer, 'prompt')
.returns(Promise.resolve({foo: 'TEST'}));
try {
await polymerInit.promptGeneratorSelection({env: yeomanEnvMock});
Expand Down Expand Up @@ -234,11 +228,11 @@ suite('init', () => {
test(testName, async () => {
const yeomanEnv = new YeomanEnvironment();
const promptStub =
sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({
sinon.stub(inquirer, 'prompt').returns(Promise.resolve({
foo: 'TEST',
}));
helpers.registerDependencies(yeomanEnv, [[
<any>function() {},
<any>function() {},
'polymer-init-custom-template:app',
]]);
try {
Expand All @@ -256,7 +250,7 @@ suite('init', () => {
});

test('prompts the user with a list', async () => {
const promptStub = sandbox.stub(inquirer, 'prompt')
const promptStub = sinon.stub(inquirer, 'prompt')
.returns(Promise.resolve({foo: 'TEST'}));

try {
Expand All @@ -270,9 +264,9 @@ suite('init', () => {

if (isPlatformWin && isMinGw) {
test('prompts with a rawlist if being used in MinGW shell', async () => {
const promptStub = sandbox.stub(inquirer, 'prompt')
const promptStub = sinon.stub(inquirer, 'prompt')
.returns(Promise.resolve({foo: 'TEST'}));
sandbox.stub(childProcess, 'execSync')
sinon.stub(childProcess, 'execSync')
.withArgs('uname -s')
.returns('mingw');

Expand Down

0 comments on commit 4a7ae2f

Please sign in to comment.