Skip to content

Commit

Permalink
test: update ava async usage to latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Apr 25, 2019
1 parent 46c1cac commit 4df0c72
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
8 changes: 4 additions & 4 deletions test/git.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ test.serial('Get the modified files, ignoring files in .gitignore but including
// Add untracked file
await outputFile('file4.js', 'Test content');

await t.deepEqual(await getModifiedFiles(), ['file4.js', 'dir/file2.js', 'file1.js']);
t.deepEqual(await getModifiedFiles(), ['file4.js', 'dir/file2.js', 'file1.js']);
});

test.serial('Returns [] if there is no modified files', async t => {
// Create a git repository, set the current working directory at the root of the repo
await gitRepo();

await t.deepEqual(await getModifiedFiles(), []);
t.deepEqual(await getModifiedFiles(), []);
});

test.serial('Commit added files', async t => {
Expand All @@ -59,7 +59,7 @@ test.serial('Commit added files', async t => {
await add(['.']);
await commit('Test commit');

await t.true((await gitGetCommits()).length === 1);
t.true((await gitGetCommits()).length === 1);
});

test.serial('Get the last commit sha', async t => {
Expand All @@ -77,7 +77,7 @@ test.serial('Throw error if the last commit sha cannot be found', async t => {
// Create a git repository, set the current working directory at the root of the repo
await gitRepo();

await t.throws(gitHead());
await t.throwsAsync(() => gitHead());
});

test.serial('Push commit to remote repository', async t => {
Expand Down
16 changes: 11 additions & 5 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test.serial('Verify authentication only on the fist call', async t => {
const nextRelease = {version: '2.0.0', gitTag: 'v2.0.0'};
const options = {repositoryUrl, branch, prepare: ['@semantic-release/npm']};

await t.notThrows(t.context.m.verifyConditions({}, {options, logger: t.context.logger}));
await t.notThrowsAsync(() => t.context.m.verifyConditions({}, {options, logger: t.context.logger}));
await t.context.m.prepare({}, {logger: t.context.logger, options: {repositoryUrl, branch}, nextRelease});
});

Expand All @@ -117,7 +117,8 @@ test('Throw SemanticReleaseError if prepare config is invalid', async t => {
const assets = true;
const options = {prepare: ['@semantic-release/npm', {path: 'semantic-release-git-branches', message, assets}]};

const errors = [...(await t.throws(t.context.m.verifyConditions({}, {options, logger: t.context.logger})))];
const verify = await t.throwsAsync(() => t.context.m.verifyConditions({}, {options, logger: t.context.logger}));
const errors = [...verify];

t.is(errors[0].name, 'SemanticReleaseError');
t.is(errors[0].code, 'EINVALIDASSETS');
Expand All @@ -129,9 +130,14 @@ test('Throw SemanticReleaseError if config is invalid', async t => {
const message = 42;
const assets = true;

const errors = [
...(await t.throws(t.context.m.verifyConditions({message, assets}, {options: {}, logger: t.context.logger}))),
];
const verify = await t.throwsAsync(() => (
t.context.m.verifyConditions(
{message, assets},
{options: {}, logger: t.context.logger}
)
));

const errors = [...verify];

t.is(errors[0].name, 'SemanticReleaseError');
t.is(errors[0].code, 'EINVALIDASSETS');
Expand Down
30 changes: 16 additions & 14 deletions test/verify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ test.afterEach.always(() => {

test('Throw SemanticReleaseError if "assets" option is not a String or false or an Array of Objects', async t => {
const assets = true;
const [error] = await t.throws(verify({assets}, {options: t.context.options}, t.context.logger));
const [error] = await t.throwsAsync(() => verify({assets}, {options: t.context.options}, t.context.logger));

t.is(error.name, 'SemanticReleaseError');
t.is(error.code, 'EINVALIDASSETS');
});

test('Throw SemanticReleaseError if "assets" option is not an Array with invalid elements', async t => {
const assets = ['file.js', 42];
const [error] = await t.throws(verify({assets}, {options: t.context.options}, t.context.logger));
const [error] = await t.throwsAsync(() => verify({assets}, {options: t.context.options}, t.context.logger));

t.is(error.name, 'SemanticReleaseError');
t.is(error.code, 'EINVALIDASSETS');
Expand All @@ -52,77 +52,79 @@ test.serial('Verify "assets" is a String', async t => {
await gitCommits(['Test commit']);
const assets = 'file2.js';

await t.notThrows(verify({assets}, {options: t.context.options}, t.context.logger));
await t.notThrowsAsync(() => verify({assets}, {options: t.context.options}, t.context.logger));
});

test.serial('Verify "assets" is an Array of String', async t => {
await gitCommits(['Test commit']);
const assets = ['file1.js', 'file2.js'];

await t.notThrows(verify({assets}, {options: t.context.options}, t.context.logger));
await t.notThrowsAsync(() => verify({assets}, {options: t.context.options}, t.context.logger));
});

test.serial('Verify "assets" is an Object with a path property', async t => {
await gitCommits(['Test commit']);
const assets = {path: 'file2.js'};

await t.notThrows(verify({assets}, {options: t.context.options}, t.context.logger));
await t.notThrowsAsync(() => verify({assets}, {options: t.context.options}, t.context.logger));
});

test.serial('Verify "assets" is an Array of Object with a path property', async t => {
await gitCommits(['Test commit']);
const assets = [{path: 'file1.js'}, {path: 'file2.js'}];

await t.notThrows(verify({assets}, {options: t.context.options}, t.context.logger));
await t.notThrowsAsync(() => verify({assets}, {options: t.context.options}, t.context.logger));
});

test.serial('Verify disabled "assets" (set to false)', async t => {
await gitCommits(['Test commit']);
const assets = false;

await t.notThrows(verify({assets}, {options: t.context.options}, t.context.logger));
await t.notThrowsAsync(() => verify({assets}, {options: t.context.options}, t.context.logger));
});

test.serial('Verify "assets" is an Array of glob Arrays', async t => {
await gitCommits(['Test commit']);
const assets = [['dist/**', '!**/*.js'], 'file2.js'];

await t.notThrows(verify({assets}, {options: t.context.options}, t.context.logger));
await t.notThrowsAsync(() => verify({assets}, {options: t.context.options}, t.context.logger));
});

test.serial('Verify "assets" is an Array of Object with a glob Arrays in path property', async t => {
await gitCommits(['Test commit']);
const assets = [{path: ['dist/**', '!**/*.js']}, {path: 'file2.js'}];

await t.notThrows(verify({assets}, {options: t.context.options}, t.context.logger));
await t.notThrowsAsync(() => verify({assets}, {options: t.context.options}, t.context.logger));
});

test('Throw SemanticReleaseError if "message" option is not a String', async t => {
const message = 42;
const [error] = await t.throws(verify({message}, {options: t.context.options}, t.context.logger));
const [error] = await t.throwsAsync(() => verify({message}, {options: t.context.options}, t.context.logger));

t.is(error.name, 'SemanticReleaseError');
t.is(error.code, 'EINVALIDMESSAGE');
});

test('Throw SemanticReleaseError if "message" option is an empty String', async t => {
const message = ' ';
const [error] = await t.throws(verify({message}, {options: t.context.options}, t.context.logger));
const [error] = await t.throwsAsync(() => verify({message}, {options: t.context.options}, t.context.logger));

t.is(error.name, 'SemanticReleaseError');
t.is(error.code, 'EINVALIDMESSAGE');
});

test('Throw SemanticReleaseError if "message" option is a whitespace String', async t => {
const message = ' \n \r ';
const [error] = await t.throws(verify({message}, {options: t.context.options}, t.context.logger));
const [error] = await t.throwsAsync(() => verify({message}, {options: t.context.options}, t.context.logger));

t.is(error.name, 'SemanticReleaseError');
t.is(error.code, 'EINVALIDMESSAGE');
});

test('Throw SemanticReleaseError if unknown branches are provided to merge with', async t => {
const [error] = await t.throws(verify({branchMerges: ['abc']}, {options: t.context.options}, t.context.logger));
const [error] = await t.throwsAsync(() => (
verify({branchMerges: ['abc']}, {options: t.context.options}, t.context.logger)
));

t.is(error.name, 'SemanticReleaseError');
t.is(error.code, 'EINVALIDMERGEBRANCH');
Expand All @@ -131,5 +133,5 @@ test('Throw SemanticReleaseError if unknown branches are provided to merge with'
test.serial('Verify undefined "message" and "assets"', async t => {
await gitCommits(['Test commit']);

await t.notThrows(verify({}, {options: t.context.options}, t.context.logger));
await t.notThrowsAsync(() => verify({}, {options: t.context.options}, t.context.logger));
});

0 comments on commit 4df0c72

Please sign in to comment.