test.beforeEach(t => { let root = document.getElementById('root'); if (!root) { root = document.createElement('div'); root.id = 'root'; document.body.appendChild(root); } t.context.root = root; });
test.before(() => { nock(URL).get('/no-cache').times(2).reply(200, {foo: 'bar'}); nock(URL).get('/cache').once().reply(200, {hello: 'world'}); nock(URL).get('/cache').twice().reply(200, {hello: 'world!'}); nock(URL).get('/cache-key?unicorn=rainbow').reply(200, {unicorn: 'rainbow'}); nock(URL).get('/cache-version').once().reply(200, {foo: 'bar'}); nock(URL).get('/cache-version').twice().reply(200, {unicorn: 'rainbow'}); });
test.serial('should fail when version is lower as latest version', async t => { await t.throwsAsync(run(testedModule('0.1.0', {name: 'test', version: '1.0.0'}, {yarn: false})), {message: 'New version `0.1.0` should be higher than current version `1.0.0`'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Validate version' && task.hasFailed())); });
test.cb('remove temporary files on cancel', t => { t.plan(1); const cp = spawn('../cli.js', ['https://sindresorhus.com', '320x240']); cp.on('exit', () => { t.false(fs.existsSync('sindresorhus.com-320x240.png')); t.end(); }); setTimeout(() => { cp.kill('SIGINT'); }, 500); });
test.before(() => { mockery.registerMock('execa', execaStub.execa); mockery.enable({ useCleanCache: true, warnOnReplace: false, warnOnUnregistered: false }); testedModule = require('../source/prerequisite-tasks'); });
test.serial('should fail when git tag already exists', async t => { execaStub.createStub([ { command: 'git rev-parse --quiet --verify refs/tags/v2.0.0', stdout: 'vvb' } ]); await t.throwsAsync(run(testedModule('2.0.0', {name: 'test', version: '1.0.0'}, {yarn: false})), {message: 'Git tag `v2.0.0` already exists.'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Check git tag existence' && task.hasFailed())); });
test.serial('.error()', async t => { const promise = hookStd.stdout(output => { promise.unhook(); t.is(JSON.parse(output).items[0].title, 'Error: foo'); }); alfyInstance.error(new Error('foo')); await promise; });
test.serial('buffer: false > promise does not resolve when output is big and "all" is used but not read', async t => { const subprocess = execa('max-buffer', {buffer: false, all: true, timeout: BUFFER_TIMEOUT}); subprocess.stdout.resume(); subprocess.stderr.resume(); const {timedOut} = await t.throwsAsync(subprocess); t.true(timedOut); });
test.serial('checks should pass', async t => { execaStub.createStub([ { command: 'git rev-parse --quiet --verify refs/tags/v2.0.0', stdout: '' } ]); await t.notThrowsAsync(run(testedModule('2.0.0', {name: 'test', version: '1.0.0'}, {yarn: false}))); });
test.beforeEach(t => { let root = document.getElementById('root'); if (!root) { root = document.createElement('div'); root.id = 'root'; document.body.appendChild(root); } t.context.root = root; });
test.beforeEach(t => { let root = document.getElementById('root'); if (!root) { root = document.createElement('div'); root.id = 'root'; document.body.appendChild(root); } t.context.root = root; });
test.serial('public-package published on npm registry: should fail when npm registry not pingable', async t => { execaStub.createStub([{ command: 'npm ping', exitCode: 1, exitCodeName: 'EPERM', stdout: '', stderr: 'failed' }]); await t.throwsAsync(run(testedModule('1.0.0', {name: 'test'}, {})), {message: 'Connection to npm registry failed'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Ping npm registry' && task.hasFailed())); });
test.serial('should fail when prerelease version of public package without dist tag given', async t => { await t.throwsAsync(run(testedModule('2.0.0-1', {name: 'test', version: '1.0.0'}, {yarn: false})), {message: 'You must specify a dist-tag using --tag when publishing a pre-release version. This prevents accidentally tagging unstable versions as "latest". https://docs.npmjs.com/cli/dist-tag'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Check for pre-release version' && task.hasFailed())); });
test.serial('should not fail when prerelease version of public package with dist tag given', async t => { execaStub.createStub([ { command: 'git rev-parse --quiet --verify refs/tags/v2.0.0', stdout: '' } ]); await t.notThrowsAsync(run(testedModule('2.0.0-1', {name: 'test', version: '1.0.0'}, {yarn: false, tag: 'pre'}))); });
test.beforeEach(t => { let root = document.getElementById('root'); if (!root) { root = document.createElement('div'); root.id = 'root'; document.body.appendChild(root); } t.context.root = root; });