From b58e0c40a7c664dbe44d713b384ed2000b89fc80 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sun, 29 Jul 2018 21:42:44 -0400 Subject: [PATCH] test: use `semanticrelease/npm-registry-docker` Docker image for tests --- test/helpers/npm-registry.js | 13 +++++++----- test/integration.test.js | 38 +++++++++++++++++------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/test/helpers/npm-registry.js b/test/helpers/npm-registry.js index cdff023c..3fed12d1 100644 --- a/test/helpers/npm-registry.js +++ b/test/helpers/npm-registry.js @@ -4,10 +4,12 @@ import got from 'got'; import delay from 'delay'; import pRetry from 'p-retry'; -const IMAGE = 'npmjs/npm-docker-couchdb:1.6.1'; +const IMAGE = 'semanticrelease/npm-registry-docker:latest'; const SERVER_PORT = 25986; const COUCHDB_PORT = 5984; const SERVER_HOST = 'localhost'; +const COUCHDB_USER = 'admin'; +const COUCHDB_PASSWORD = 'password'; const NPM_USERNAME = 'integration'; const NPM_PASSWORD = 'suchsecure'; const NPM_EMAIL = 'integration@test.com'; @@ -15,7 +17,7 @@ const docker = new Docker(); let container; /** - * Download the `npm-docker-couchdb` Docker image, create a new container and start it. + * Download the `npm-registry-docker` Docker image, create a new container and start it. */ async function start() { await getStream(await docker.pull(IMAGE)); @@ -24,10 +26,11 @@ async function start() { Tty: true, Image: IMAGE, PortBindings: {[`${COUCHDB_PORT}/tcp`]: [{HostPort: `${SERVER_PORT}`}]}, + Env: [`COUCHDB_USER=${COUCHDB_USER}`, `COUCHDB_PASSWORD=${COUCHDB_PASSWORD}`], }); await container.start(); - await delay(3000); + await delay(4000); try { // Wait for the registry to be ready @@ -43,7 +46,7 @@ async function start() { // Create user await got(`http://${SERVER_HOST}:${SERVER_PORT}/_users/org.couchdb.user:${NPM_USERNAME}`, { json: true, - auth: 'admin:admin', + auth: `${COUCHDB_USER}:${COUCHDB_PASSWORD}`, method: 'PUT', body: { _id: `org.couchdb.user:${NPM_USERNAME}`, @@ -66,7 +69,7 @@ const authEnv = { }; /** - * Stop and remote the `npm-docker-couchdb` Docker container. + * Stop and remote the `npm-registry-docker` Docker container. */ async function stop() { await container.stop(); diff --git a/test/integration.test.js b/test/integration.test.js index e4dfeed9..1dc53b50 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -7,10 +7,17 @@ import tempy from 'tempy'; import clearModule from 'clear-module'; import npmRegistry from './helpers/npm-registry'; -const LEGACY_TOKEN = Buffer.from( - `${npmRegistry.authEnv.NPM_USERNAME}:${npmRegistry.authEnv.NPM_PASSWORD}`, - 'utf8' -).toString('base64'); +/* eslint camelcase: ["error", {properties: "never"}] */ + +// Environment variables used only for the local npm command used to do verification +const testEnv = { + ...process.env, + ...npmRegistry.authEnv, + npm_config_registry: npmRegistry.url, + LEGACY_TOKEN: Buffer.from(`${npmRegistry.authEnv.NPM_USERNAME}:${npmRegistry.authEnv.NPM_PASSWORD}`, 'utf8').toString( + 'base64' + ), +}; test.before(async () => { // Start the local NPM registry @@ -189,10 +196,7 @@ test('Publish the package', async t => { t.deepEqual(result, {name: 'npm package (@latest dist-tag)', url: undefined}); t.is((await readJson(path.resolve(cwd, 'package.json'))).version, '1.0.0'); t.false(await pathExists(path.resolve(cwd, `${pkg.name}-1.0.0.tgz`))); - t.is( - await execa.stdout('npm', ['view', pkg.name, 'version'], {cwd, env: {...npmRegistry.authEnv, LEGACY_TOKEN}}), - '1.0.0' - ); + t.is(await execa.stdout('npm', ['view', pkg.name, 'version'], {cwd, env: testEnv}), '1.0.0'); }); test('Publish the package on a dist-tag', async t => { @@ -209,10 +213,7 @@ test('Publish the package on a dist-tag', async t => { t.deepEqual(result, {name: 'npm package (@next dist-tag)', url: 'https://www.npmjs.com/package/publish-tag'}); t.is((await readJson(path.resolve(cwd, 'package.json'))).version, '1.0.0'); t.false(await pathExists(path.resolve(cwd, `${pkg.name}-1.0.0.tgz`))); - t.is( - await execa.stdout('npm', ['view', pkg.name, 'version'], {cwd, env: {...npmRegistry.authEnv, LEGACY_TOKEN}}), - '1.0.0' - ); + t.is(await execa.stdout('npm', ['view', pkg.name, 'version'], {cwd, env: testEnv}), '1.0.0'); }); test('Publish the package from a sub-directory', async t => { @@ -229,10 +230,7 @@ test('Publish the package from a sub-directory', async t => { t.deepEqual(result, {name: 'npm package (@latest dist-tag)', url: undefined}); t.is((await readJson(path.resolve(cwd, 'dist/package.json'))).version, '1.0.0'); t.false(await pathExists(path.resolve(cwd, `${pkg.name}-1.0.0.tgz`))); - t.is( - await execa.stdout('npm', ['view', pkg.name, 'version'], {cwd, env: {...npmRegistry.authEnv, LEGACY_TOKEN}}), - '1.0.0' - ); + t.is(await execa.stdout('npm', ['view', pkg.name, 'version'], {cwd, env: testEnv}), '1.0.0'); }); test('Create the package and skip publish ("npmPublish" is false)', async t => { @@ -249,7 +247,7 @@ test('Create the package and skip publish ("npmPublish" is false)', async t => { t.falsy(result); t.is((await readJson(path.resolve(cwd, 'package.json'))).version, '1.0.0'); t.true(await pathExists(path.resolve(cwd, `tarball/${pkg.name}-1.0.0.tgz`))); - await t.throws(execa('npm', ['view', pkg.name, 'version'], {cwd, env: {...npmRegistry.authEnv, LEGACY_TOKEN}})); + await t.throws(execa('npm', ['view', pkg.name, 'version'], {cwd, env: testEnv})); }); test('Create the package and skip publish ("package.private" is true)', async t => { @@ -266,7 +264,7 @@ test('Create the package and skip publish ("package.private" is true)', async t t.falsy(result); t.is((await readJson(path.resolve(cwd, 'package.json'))).version, '1.0.0'); t.true(await pathExists(path.resolve(cwd, `tarball/${pkg.name}-1.0.0.tgz`))); - await t.throws(execa('npm', ['view', pkg.name, 'version'], {cwd, env: {...npmRegistry.authEnv, LEGACY_TOKEN}})); + await t.throws(execa('npm', ['view', pkg.name, 'version'], {cwd, env: testEnv})); }); test('Create the package and skip publish from a sub-directory ("npmPublish" is false)', async t => { @@ -283,7 +281,7 @@ test('Create the package and skip publish from a sub-directory ("npmPublish" is t.falsy(result); t.is((await readJson(path.resolve(cwd, 'dist/package.json'))).version, '1.0.0'); t.true(await pathExists(path.resolve(cwd, `tarball/${pkg.name}-1.0.0.tgz`))); - await t.throws(execa('npm', ['view', pkg.name, 'version'], {cwd, env: {...npmRegistry.authEnv, LEGACY_TOKEN}})); + await t.throws(execa('npm', ['view', pkg.name, 'version'], {cwd, env: testEnv})); }); test('Create the package and skip publish from a sub-directory ("package.private" is true)', async t => { @@ -305,7 +303,7 @@ test('Create the package and skip publish from a sub-directory ("package.private t.falsy(result); t.is((await readJson(path.resolve(cwd, 'dist/package.json'))).version, '1.0.0'); t.true(await pathExists(path.resolve(cwd, `tarball/${pkg.name}-1.0.0.tgz`))); - await t.throws(execa('npm', ['view', pkg.name, 'version'], {cwd, env: {...npmRegistry.authEnv, LEGACY_TOKEN}})); + await t.throws(execa('npm', ['view', pkg.name, 'version'], {cwd, env: testEnv})); }); test('Throw SemanticReleaseError Array if config option are not valid in publish', async t => {