Skip to content

Commit

Permalink
Switch to the native Node.js test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 23, 2024
1 parent 39ae3aa commit a5df823
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 189 deletions.
67 changes: 0 additions & 67 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@
"devDependencies": {
"@xhmikosr/bin-check": "^7.0.3",
"c8": "^9.1.0",
"uvu": "^0.5.6",
"xo": "^0.58.0"
},
"scripts": {
"lint": "xo",
"fix": "xo --fix",
"uvu": "uvu test",
"test": "npm run lint && npm run uvu",
"test:ci": "c8 npm run uvu",
"test": "npm run lint && node --test",
"test:ci": "c8 node --test",
"postinstall": "node lib/install.js"
},
"xo": {
Expand Down
216 changes: 107 additions & 109 deletions test/options.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import fs from 'node:fs/promises';
import process from 'node:process';
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import { beforeEach, describe, it } from 'node:test';
import hugoBin from '../lib/index.js';

const pkg = new URL('../package.json', import.meta.url);
Expand All @@ -16,111 +16,109 @@ const environmentVariables = [
'npm_config_hugo_bin_hugo_version'
];

const testSuite = suite('options');

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

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

// Default Repository - Test Cases
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);

for (const sourceUrl of repoSources) {
assert.is(sourceUrl.startsWith('https://github.com/'), true);
}
});

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);

for (const sourceUrl of repoSources) {
assert.is(sourceUrl.startsWith('https://github.com/'), true);
}
});

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);

for (const sourceUrl of repoSources) {
assert.is(sourceUrl.startsWith('https://github.com/'), true);
}
describe('options', () => {
beforeEach(() => {
for (const variable of environmentVariables) {
// Ensure that the environment is cleaned before next test run.
delete process.env[variable];
}
});

it('verify test env', () => {
for (const variable of environmentVariables) {
assert.equal(process.env[variable], undefined);
}
});

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

for (const sourceUrl of repoSources) {
assert.equal(sourceUrl.startsWith('https://github.com/'), true);
}
});

it('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);

for (const sourceUrl of repoSources) {
assert.equal(sourceUrl.startsWith('https://github.com/'), true);
}
});

it('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);

for (const sourceUrl of repoSources) {
assert.equal(sourceUrl.startsWith('https://github.com/'), true);
}
});

// Custom/Enterprise Repository Test Cases
it('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);

for (const sourceUrl of repoSources) {
assert.equal(sourceUrl.startsWith('https://some1.example.com/'), true);
}
});

it('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());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.equal(sourceUrl.startsWith('https://some2.example.com/'), true);
}
});

it('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());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.equal(sourceUrl.startsWith('https://some3.example.com/'), true);
}
});

it('should return default version', async() => {
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.equal(sourceUrl.startsWith(`https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/`), true);
}
});

it('should return custom version', async() => {
process.env.npm_config_hugo_bin_hugo_version = '122.0';
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.equal(sourceUrl.startsWith('https://github.com/gohugoio/hugo/releases/download/v122.0/'), true);
}
});

it('should strip `v` from custom version', async() => {
process.env.npm_config_hugo_bin_hugo_version = 'v122.0';
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.equal(sourceUrl.startsWith('https://github.com/gohugoio/hugo/releases/download/v122.0/'), true);
}
});
});

// Custom/Enterprise Repository Test Cases
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);

for (const sourceUrl of repoSources) {
assert.is(sourceUrl.startsWith('https://some1.example.com/'), true);
}
});

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());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.is(sourceUrl.startsWith('https://some2.example.com/'), true);
}
});

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());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.is(sourceUrl.startsWith('https://some3.example.com/'), true);
}
});

testSuite('should return default version', async() => {
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.is(sourceUrl.startsWith(`https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/`), true);
}
});

testSuite('should return custom version', async() => {
process.env.npm_config_hugo_bin_hugo_version = '122.0';
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.is(sourceUrl.startsWith('https://github.com/gohugoio/hugo/releases/download/v122.0/'), true);
}
});

testSuite('should strip `v` from custom version', async() => {
process.env.npm_config_hugo_bin_hugo_version = 'v122.0';
const lib = await hugoBin(process.cwd());
const repoSources = lib._src.map(v => v.url);

for (const sourceUrl of repoSources) {
assert.is(sourceUrl.startsWith('https://github.com/gohugoio/hugo/releases/download/v122.0/'), true);
}
});

testSuite.run();
17 changes: 8 additions & 9 deletions test/works.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';
import binCheck from '@xhmikosr/bin-check';
import { suite } from 'uvu';
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);
describe('works', () => {
it('should return path to binary and work', () => {
return binCheck(hugoPath, ['version']).then(works => {
assert.ok(works);
});
});
});

testSuite.run();

0 comments on commit a5df823

Please sign in to comment.