Skip to content

Commit

Permalink
add tests for cache commands
Browse files Browse the repository at this point in the history
  • Loading branch information
voxsim committed Mar 20, 2017
1 parent 6e9a9a6 commit a2885c9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions __tests__/commands/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* @flow */

import * as reporters from '../../src/reporters/index.js';
import * as fs from '../../src/util/fs.js';
import {run} from '../../src/cli/commands/cache.js';
import {run as buildRun, runInstall} from './_helpers.js';

const path = require('path');
const stream = require('stream');

const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'cache');

const runCache = buildRun.bind(
null,
reporters.ConsoleReporter,
fixturesLoc,
async (args, flags, config, reporter, lockfile, getStdout): Promise<string> => {
await run(config, reporter, flags, args);
return getStdout();
},
);

test('ls', async (): Promise<void> => {
await runInstall({}, 'artifacts-finds-and-saves', async (config): Promise<void> => {
const out = new stream.PassThrough();
const reporter = new reporters.ConsoleReporter({stdout: out});
await run(config, reporter, {}, ['ls']);
const stdout = String(out.read());
expect(stdout).toContain('dummy');
expect(stdout).toContain('0.0.0');
});
});

test('ls with scoped package', async (): Promise<void> => {
await runInstall({}, 'install-from-authed-private-registry', async (config): Promise<void> => {
const out = new stream.PassThrough();
const reporter = new reporters.ConsoleReporter({stdout: out});
await run(config, reporter, {}, ['ls']);
const stdout = String(out.read());
expect(stdout).toContain('@types/lodash');
expect(stdout).toContain('4.14.37');
});
});

test('dir', async (): Promise<void> => {
await runCache(['dir'], {}, '', (config, reporter, stdout) => {
expect(stdout).toContain(config.cacheFolder);
});
});

test('clean', async (): Promise<void> => {
await runInstall({}, 'artifacts-finds-and-saves', async (config): Promise<void> => {
let files = await fs.readdir(config.cacheFolder);
expect(files.length).toEqual(2); // we need to add one .tmp folder

const out = new stream.PassThrough();
const reporter = new reporters.ConsoleReporter({stdout: out});
await run(config, reporter, {}, ['clean']);

expect(await fs.exists(config.cacheFolder)).toBeTruthy();

files = await fs.readdir(config.cacheFolder);
expect(files.length).toEqual(0);
});
});
Empty file.

0 comments on commit a2885c9

Please sign in to comment.