From 8e9ec886cca32a126528f49772714ce1e718e9cb Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Wed, 9 Nov 2016 14:22:13 +0000 Subject: [PATCH] added a test for #1733 (#1754) --- __tests__/commands/add.js | 30 +++++++++++++++++-- .../fixtures/add/integrity-check/.gitkeep | 0 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 __tests__/fixtures/add/integrity-check/.gitkeep diff --git a/__tests__/commands/add.js b/__tests__/commands/add.js index a7d18c191c..426caf951e 100644 --- a/__tests__/commands/add.js +++ b/__tests__/commands/add.js @@ -538,7 +538,33 @@ test.concurrent('add should store latest version in lockfile', (): Promise const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock'))); const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); - assert(lockfile.indexOf('max-safe-integer@^1.0.1:') === 0); - assert.deepEqual(pkg.dependencies, {'max-safe-integer': '^1.0.1'}); + const version = pkg.dependencies['max-safe-integer']; + assert(semver.valid(version.slice(1))); + assert(lockfile.indexOf('max-safe-integer:') === -1); + assert(lockfile.indexOf(`max-safe-integer@${version}:`) === 0); }); }); + +// TODO disabled until https://github.com/yarnpkg/yarn/issues/1733 is fixed +test.skip('add should generate correct integrity file', (): Promise => { + return runAdd({}, ['mime-db@1.24.0'], 'integrity-check', async (config, reporter) => { + let allCorrect = true; + try { + await check(config, reporter, {integrity: true}, []); + } catch (err) { + allCorrect = false; + } + expect(allCorrect).toBe(true); + + // add to an existing package.json caused incorrect integrity https://github.com/yarnpkg/yarn/issues/1733 + const add = new Add(['left-pad@1.1.3'], {}, config, reporter, await Lockfile.fromDirectory(config.cwd)); + await add.init(); + try { + await check(config, reporter, {integrity: true}, []); + } catch (err) { + allCorrect = false; + } + expect(allCorrect).toBe(true); + }); + +}); diff --git a/__tests__/fixtures/add/integrity-check/.gitkeep b/__tests__/fixtures/add/integrity-check/.gitkeep new file mode 100644 index 0000000000..e69de29bb2