Refactor tests

This commit is contained in:
XhmikosR committed 2023-05-18 08:14:01 +03:00
1 parent ce2efe7734
commit 2d54c7c2d7
2 files changed
+39 -26

No files matched your search

@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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());
@@ -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());
@@ -93,4 +92,4 @@ customRepoSuite('should return custom repository url - Repository: custom - Exte
}
});
customRepoSuite.run();
testSuite.run();
+14
View File
@@ -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();