Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed May 18, 2023
1 parent ce2efe7 commit 2d54c7c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
51 changes: 25 additions & 26 deletions test/index.js → test/custom-repository.test.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
import process from 'node:process';
import binCheck from 'bin-check';
import { suite } from 'uvu';
import * as assert from 'uvu/assert'; // eslint-disable-line n/file-extension-in-import
import hugoPath from '../index.js';
// eslint-disable-next-line n/file-extension-in-import
import * as assert from 'uvu/assert';
import hugoBin from '../lib/index.js';

const worksSuite = suite('works');

worksSuite('should return path to binary and work', async() => {
const works = await binCheck(hugoPath, ['version']);
assert.is(works, true);
});

worksSuite.run();
const environmentVariables = [
'HUGO_BIN_BUILD_TAGS',
'npm_config_hugo_bin_build_tags',
'HUGO_BIN_DOWNLOAD_REPO',
'npm_config_hugo_bin_download_repo'
];

/**
* Verify Custom/Enterprise Repository overwrite.
*/
const customRepoSuite = suite('overwrites download repository');
const testSuite = suite('overwrites download repository');

customRepoSuite.before.each(() => {
// Ensure that the environment is cleaned before next test run.
delete process.env.npm_config_hugo_bin_build_tags;
delete process.env.npm_config_hugo_bin_download_repo;
testSuite.before.each(() => {
for (const variable of environmentVariables) {
// Ensure that the environment is cleaned before next test run.
delete process.env[variable];
}
});

customRepoSuite('verify test env', () => {
assert.is(process.env.npm_config_hugo_bin_build_tags, undefined);
assert.is(process.env.npm_config_hugo_bin_download_repo, undefined);
testSuite('verify test env', () => {
for (const variable of environmentVariables) {
assert.is(process.env[variable], undefined);
}
});

// Default Repository - Test Cases
customRepoSuite('should return default repository url - Repository: default - Extended: undefined', async() => {
testSuite('should return default repository url - Repository: default - Extended: undefined', async() => {
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);

Expand All @@ -40,7 +39,7 @@ customRepoSuite('should return default repository url - Repository: default - Ex
}
});

customRepoSuite('should return default repository url - Repository: default - Extended: empty', async() => {
testSuite('should return default repository url - Repository: default - Extended: empty', async() => {
process.env.npm_config_hugo_bin_build_tags = '';
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);
Expand All @@ -50,7 +49,7 @@ customRepoSuite('should return default repository url - Repository: default - Ex
}
});

customRepoSuite('should return default repository url - Repository: default - Extended: extended', async() => {
testSuite('should return default repository url - Repository: default - Extended: extended', async() => {
process.env.npm_config_hugo_bin_build_tags = 'extended';
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);
Expand All @@ -61,7 +60,7 @@ customRepoSuite('should return default repository url - Repository: default - Ex
});

// Custom/Enterprise Repository Test Cases
customRepoSuite('should return custom repository url - Repository: custom - Extended: undefined', async() => {
testSuite('should return custom repository url - Repository: custom - Extended: undefined', async() => {
process.env.npm_config_hugo_bin_download_repo = 'https://some1.example.com';
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);
Expand All @@ -71,7 +70,7 @@ customRepoSuite('should return custom repository url - Repository: custom - Exte
}
});

customRepoSuite('should return custom repository url - Repository: custom - Extended: empty', async() => {
testSuite('should return custom repository url - Repository: custom - Extended: empty', async() => {
process.env.npm_config_hugo_bin_build_tags = '';
process.env.npm_config_hugo_bin_download_repo = 'https://some2.example.com';
const lib = await hugoBin(process.cwd());
Expand All @@ -82,7 +81,7 @@ customRepoSuite('should return custom repository url - Repository: custom - Exte
}
});

customRepoSuite('should return custom repository url - Repository: custom - Extended: extended', async() => {
testSuite('should return custom repository url - Repository: custom - Extended: extended', async() => {
process.env.npm_config_hugo_bin_build_tags = 'extended';
process.env.npm_config_hugo_bin_download_repo = 'https://some3.example.com';
const lib = await hugoBin(process.cwd());
Expand All @@ -93,4 +92,4 @@ customRepoSuite('should return custom repository url - Repository: custom - Exte
}
});

customRepoSuite.run();
testSuite.run();
14 changes: 14 additions & 0 deletions test/works.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import binCheck from 'bin-check';
import { suite } from 'uvu';
// eslint-disable-next-line n/file-extension-in-import
import * as assert from 'uvu/assert';
import hugoPath from '../index.js';

const testSuite = suite('works');

testSuite('should return path to binary and work', async() => {
const works = await binCheck(hugoPath, ['version']);
assert.is(works, true);
});

testSuite.run();

0 comments on commit 2d54c7c

Please sign in to comment.