Skip to content

Commit

Permalink
Merge bda8467 into c09d363
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Dec 22, 2019
2 parents c09d363 + bda8467 commit 51ffff0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
47 changes: 47 additions & 0 deletions src/__tests__/bin.spec.ts
@@ -0,0 +1,47 @@
import * as fs from 'fs';
import { exec } from '../bin';

describe('bin', () => {
let logSpy;
let debugSpy;

beforeEach(() => {
logSpy = jest.spyOn(console, 'log');
debugSpy = jest.spyOn(console, 'debug');
jest.resetAllMocks();
});

it('should execute ok tests', async () => {
await exec({ config: './tests/ok_every.config.js' });
expect(logSpy).toHaveBeenNthCalledWith(1, '🔍 Checking software requirements...');
expect(logSpy).toHaveBeenNthCalledWith(3, '✅ All is well!');
});

it('should execute nok tests', async () => {
try {
await exec({ config: './tests/ok_some.config.js' });
} catch (err) {
expect(err).toMatchInlineSnapshot(`[Error: ❌ Not all requirements are satisfied]`);
}
});

it('should execute nok --force tests', async () => {
await exec({ config: './tests/ok_some.config.js', force: true });
expect(logSpy).toHaveBeenNthCalledWith(3, '⚠️ Not all requirements are satisfied (--force)');
});

it('should print debug data with --debug', async () => {
await exec({ config: './tests/ok_every.config.js', debug: true });
expect(debugSpy).toHaveBeenCalled();
});

it('should scaffold with --init', async () => {
const filePath = './requirements.config.js';

await exec({ init: true });
expect(fs.existsSync(filePath)).toBe(true);

// clean up
fs.unlinkSync(filePath);
});
});
4 changes: 2 additions & 2 deletions src/bin.ts
Expand Up @@ -6,8 +6,8 @@ import { renderTable } from './reporter';
import { Configuration } from './types';
import { scaffold } from './scaffold';

export async function exec() {
const argv = getArgv();
export async function exec(_debug_argv_?) {
const argv = _debug_argv_ ?? getArgv();

if (argv.init) {
scaffold();
Expand Down

0 comments on commit 51ffff0

Please sign in to comment.