Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jul 30, 2021
1 parent dae3a51 commit 9516010
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -46,7 +46,7 @@
"scripts": {
"lint": "eslint lib test",
"format": "prettier --write \"{lib,test}/**/*.js\"",
"test": "ava",
"test": "ava --timeout=20m",
"coverage": "nyc --reporter=lcov --reporter=html --config=config/.codecov.yml npm test",
"codecov": "nyc --reporter=json --config=config/.codecov.yml npm test && codecov -f coverage/coverage-final.json",
"readme": "markdown-toc README.md -i --maxdepth=2 --bullets=-",
Expand Down
24 changes: 15 additions & 9 deletions test/github.js
Expand Up @@ -221,7 +221,9 @@ test('should release to git.pushRepo', async t => {
exec.restore();
});

test('should throw for unauthenticated user', async t => {
const testSkipOnActions = process.env.GITHUB_ACTIONS ? test.skip : test;

testSkipOnActions('should throw for unauthenticated user', async t => {
const options = { github: { tokenRef, pushRepo, host } };
const github = factory(GitHub, { options });
const stub = sinon.stub(github.client.users, 'getAuthenticated');
Expand All @@ -235,7 +237,7 @@ test('should throw for unauthenticated user', async t => {
stub.restore();
});

test('should throw for non-collaborator', async t => {
testSkipOnActions('should throw for non-collaborator', async t => {
interceptAuthentication({ username: 'john' });
const options = { github: { tokenRef, pushRepo, host } };
const github = factory(GitHub, { options });
Expand All @@ -248,10 +250,11 @@ test('should throw for non-collaborator', async t => {
});

test.serial('should skip authentication and collaborator checks when running on GitHub Actions', async t => {
const GITHUB_ACTIONS = process.env.GITHUB_ACTIONS;
const GITHUB_ACTOR = process.env.GITHUB_ACTOR;
process.env.GITHUB_ACTIONS = 1;
process.env.GITHUB_ACTOR = 'release-it';
const { GITHUB_ACTIONS, GITHUB_ACTOR } = process.env;
if (!GITHUB_ACTIONS) {
process.env.GITHUB_ACTIONS = 1;
process.env.GITHUB_ACTOR = 'webpro';
}

const options = { github: { tokenRef } };
const github = factory(GitHub, { options });
Expand All @@ -262,12 +265,15 @@ test.serial('should skip authentication and collaborator checks when running on

t.is(authStub.callCount, 0);
t.is(collaboratorStub.callCount, 0);
t.is(github.getContext('username'), 'release-it');
t.is(github.getContext('username'), 'webpro');

authStub.restore();
collaboratorStub.restore();
process.env.GITHUB_ACTIONS = GITHUB_ACTIONS ?? '';
process.env.GITHUB_ACTOR = GITHUB_ACTOR ?? '';

if (!GITHUB_ACTIONS) {
process.env.GITHUB_ACTIONS = GITHUB_ACTIONS || '';
process.env.GITHUB_ACTOR = GITHUB_ACTOR || '';
}
});

test('should handle octokit client error (without retries)', async t => {
Expand Down
16 changes: 10 additions & 6 deletions test/plugins.js
Expand Up @@ -52,13 +52,15 @@ test.serial('should instantiate plugins and execute all release-cycle methods',

sh.mkdir('my-plugin');
sh.pushd('-q', 'my-plugin');
sh.exec('npm link release-it');
sh.exec('npm init -f');
sh.exec('npm install release-it');
sh.ShellString("const { Plugin } = require('release-it'); module.exports = " + MyPlugin.toString()).toEnd('index.js');
sh.popd();

sh.mkdir('-p', 'my/plugin');
sh.pushd('-q', 'my/plugin');
sh.exec('npm link release-it');
sh.exec('npm init -f');
sh.exec('npm install release-it');
sh.ShellString("const { Plugin } = require('release-it'); module.exports = " + MyPlugin.toString()).toEnd('index.js');
sh.popd();

Expand All @@ -67,7 +69,7 @@ test.serial('should instantiate plugins and execute all release-cycle methods',
'my-plugin': {
name: 'foo'
},
'./my/plugin': [
'./my/plugin/index.js': [
'named-plugin',
{
name: 'bar'
Expand Down Expand Up @@ -111,7 +113,8 @@ test.serial('should disable core plugins', async t => {
sh.exec('npm init -f');
sh.mkdir('replace-plugin');
sh.pushd('-q', 'replace-plugin');
sh.exec('npm link release-it');
sh.exec('npm init -f');
sh.exec('npm install release-it');
const content = "const { Plugin } = require('release-it'); module.exports = " + ReplacePlugin.toString();
sh.ShellString(content).toEnd('index.js');
sh.popd();
Expand All @@ -138,7 +141,7 @@ test.serial('should support ESM-based plugins', async t => {
sh.mkdir('my-plugin');
sh.pushd('-q', 'my-plugin');
sh.ShellString('{"name":"my-plugin","version":"1.0.0","type": "module"}').toEnd('package.json');
sh.exec('npm link release-it');
sh.exec('npm install release-it@esm');
const content = "import { Plugin } from 'release-it'; " + MyPlugin.toString() + '; export default MyPlugin;';
sh.ShellString(content).toEnd('index.js');
sh.popd();
Expand Down Expand Up @@ -166,7 +169,8 @@ test.serial('should expose context to execute commands', async t => {

sh.mkdir('context-plugin');
sh.pushd('-q', 'context-plugin');
sh.exec('npm link release-it');
sh.exec('npm init -f');
sh.exec('npm install release-it');
const content = "const { Plugin } = require('release-it'); module.exports = " + ContextPlugin.toString();
sh.ShellString(content).toEnd('index.js');
sh.popd();
Expand Down
2 changes: 1 addition & 1 deletion test/tasks.js
Expand Up @@ -401,7 +401,7 @@ test.serial('should propagate errors', async t => {
sh.mkdir('my-plugin');
sh.pushd('-q', 'my-plugin');
sh.exec('npm init -f');
sh.exec('npm link release-it');
sh.exec('npm install release-it');
const plugin = "const { Plugin } = require('release-it'); module.exports = class MyPlugin extends Plugin {};";
sh.ShellString(plugin).toEnd('index.js');
sh.popd();
Expand Down

0 comments on commit 9516010

Please sign in to comment.