From 2d54c7c2d730ab7a740d59e94e48c41de30f20a8 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 17 May 2023 14:39:26 +0300 Subject: [PATCH] Refactor tests --- test/{index.js => custom-repository.test.js} | 51 ++++++++++---------- test/works.test.js | 14 ++++++ 2 files changed, 39 insertions(+), 26 deletions(-) rename test/{index.js => custom-repository.test.js} (56%) create mode 100644 test/works.test.js diff --git a/test/index.js b/test/custom-repository.test.js similarity index 56% rename from test/index.js rename to test/custom-repository.test.js index efcdbde..698720c 100644 --- a/test/index.js +++ b/test/custom-repository.test.js @@ -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(); diff --git a/test/works.test.js b/test/works.test.js new file mode 100644 index 0000000..5a96699 --- /dev/null +++ b/test/works.test.js @@ -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();