diff --git a/__tests__/commands/cache.js b/__tests__/commands/cache.js new file mode 100644 index 0000000000..7eef636662 --- /dev/null +++ b/__tests__/commands/cache.js @@ -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 => { + await run(config, reporter, flags, args); + return getStdout(); + }, +); + +test('ls', async (): Promise => { + await runInstall({}, 'artifacts-finds-and-saves', async (config): Promise => { + 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 => { + await runInstall({}, 'install-from-authed-private-registry', async (config): Promise => { + 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 => { + await runCache(['dir'], {}, '', (config, reporter, stdout) => { + expect(stdout).toContain(config.cacheFolder); + }); +}); + +test('clean', async (): Promise => { + await runInstall({}, 'artifacts-finds-and-saves', async (config): Promise => { + 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); + }); +}); diff --git a/__tests__/fixtures/cache/.gitkeep b/__tests__/fixtures/cache/.gitkeep new file mode 100644 index 0000000000..e69de29bb2