Skip to content

Commit

Permalink
test: use semanticrelease/npm-registry-docker Docker image for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jul 30, 2018
1 parent 0b9688a commit b58e0c4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
13 changes: 8 additions & 5 deletions test/helpers/npm-registry.js
Expand Up @@ -4,18 +4,20 @@ 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';
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));
Expand All @@ -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
Expand All @@ -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}`,
Expand All @@ -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();
Expand Down
38 changes: 18 additions & 20 deletions test/integration.test.js
Expand Up @@ -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
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand Down

0 comments on commit b58e0c4

Please sign in to comment.