Skip to content

Commit

Permalink
Adds a test to check that the cache path is correctly updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël Nison committed Feb 28, 2017
1 parent c4b64a4 commit 3dec8d4
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 83 deletions.
38 changes: 36 additions & 2 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* @flow */

import type Config from '../../../src/config';
import {run as cache} from '../../../src/cli/commands/cache.js';
import {run as check} from '../../../src/cli/commands/check.js';
import * as constants from '../../../src/constants.js';
import * as reporters from '../../../src/reporters/index.js';
Expand All @@ -11,15 +13,32 @@ import {promisify} from '../../../src/util/promise';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;

const request = require('request');
let request = require('request');
const assert = require('assert');
const semver = require('semver');
const fsNode = require('fs');
const path = require('path');
const stream = require('stream');
const os = require('os');

async function mockConstants(mocks: Object, cb: (config: Config) => Promise<void>): Promise<void> {
// We cannot put this function inside _helpers, because we need to change the "request" variable
// after resetting the modules. Updating this variable is required because some tests check what
// happened during the Yarn execution, and they need to use the same instance of "request" than
// the Yarn environment.

const automock = jest.genMockFromModule('../../../src/constants');
jest.setMock('../../../src/constants', Object.assign(automock, mocks));

jest.resetModules();
request = require('request');

jest.mock('../../../src/constants');
await cb(await require('../../../src/config.js').default.create());
jest.unmock('../../../src/constants');
}

beforeEach(request.__resetAuthedRequests);
// $FlowFixMe
afterEach(request.__resetAuthedRequests);

test.concurrent('properly find and save build artifacts', async () => {
Expand All @@ -37,6 +56,21 @@ test.concurrent('properly find and save build artifacts', async () => {
});
});

test('changes the cache path when bumping the cache version', async () => {
await runInstall({}, 'install-github', async (config): Promise<void> => {
const inOut = new stream.PassThrough();
const reporter = new reporters.JSONReporter({stdout: inOut});

await cache(config, reporter, {}, ['dir']);
assert.ok(!!(JSON.parse(String(inOut.read())) : any).data.match(/\/v1\/?$/));

await mockConstants({CACHE_VERSION: 42}, async (config): Promise<void> => {
await cache(config, reporter, {}, ['dir']);
assert.ok(!!(JSON.parse(String(inOut.read())) : any).data.match(/\/v42\/?$/));
});
});
});

test.concurrent("removes extraneous files that aren't in module or artifacts", async () => {
async function check(cwd: string): Promise<void> {
// retains artifact
Expand Down
13 changes: 8 additions & 5 deletions __tests__/package-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ function addTest(pattern, registry = 'npm', init: ?(cacheFolder: string) => Prom
const reporter = new reporters.NoopReporter({});

const loc = await makeTemp();
await fs.mkdirp(path.join(loc, 'node_modules'));
const cacheFolder = path.join(loc, 'cache');
await fs.mkdirp(cacheFolder);
if (init) {
await init(cacheFolder);
}

const config = await Config.create({
cwd: loc,
offline,
cacheFolder,
}, reporter);

await fs.mkdirp(path.join(loc, 'node_modules'));
await fs.mkdirp(config.cacheFolder);

if (init) {
await init(config.cacheFolder);
}

const resolver = new PackageResolver(config, lockfile);
await resolver.init([{pattern, registry}]);

Expand Down
73 changes: 0 additions & 73 deletions flow-typed/npm/jest_v14.0.x.js

This file was deleted.

Loading

0 comments on commit 3dec8d4

Please sign in to comment.