mirror of
https://github.com/acamarata/moon-cycle.git
synced 2026-06-30 18:54:29 +00:00
- Add input validation (TypeError) to cycleMonth and cycleYear - Convert tests to node:test runner with describe/it structure - Add ESLint + Prettier with lint, format, and format:check scripts - Update CI workflow with lint job, frozen-lockfile, and pack-check - Add noImplicitReturns, noFallthroughCasesInSwitch, skipLibCheck to tsconfig - Add invalid Date tests for both ESM and CJS suites
75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
/**
|
|
* CJS test suite for moon-cycle v2.
|
|
* Verifies CommonJS compatibility of the built package.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { describe, it } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const {
|
|
cycleMonth,
|
|
cycleYear,
|
|
imageFolder,
|
|
cdnUrl,
|
|
SYNODIC_MONTH,
|
|
MONTH_IMAGES,
|
|
YEAR_IMAGES,
|
|
MONTH_ANCHOR,
|
|
YEAR_ANCHOR,
|
|
} = require('./dist/index.cjs');
|
|
|
|
describe('CJS exports', () => {
|
|
it('all exports are available via require()', () => {
|
|
assert.strictEqual(typeof cycleMonth, 'function');
|
|
assert.strictEqual(typeof cycleYear, 'function');
|
|
assert.strictEqual(typeof imageFolder, 'function');
|
|
assert.strictEqual(typeof cdnUrl, 'function');
|
|
assert.strictEqual(typeof SYNODIC_MONTH, 'number');
|
|
assert.strictEqual(typeof MONTH_IMAGES, 'number');
|
|
assert.strictEqual(typeof YEAR_IMAGES, 'number');
|
|
assert(MONTH_ANCHOR instanceof Date);
|
|
assert(YEAR_ANCHOR instanceof Date);
|
|
});
|
|
|
|
it('cycleMonth at anchor returns 001.webp', () => {
|
|
assert.strictEqual(cycleMonth(MONTH_ANCHOR), '001.webp');
|
|
});
|
|
|
|
it('cycleYear at anchor returns 0001.webp', () => {
|
|
assert.strictEqual(cycleYear(YEAR_ANCHOR), '0001.webp');
|
|
});
|
|
|
|
it('cycleMonth result format is correct', () => {
|
|
assert.match(cycleMonth(), /^\d{3}\.webp$/);
|
|
});
|
|
|
|
it('cycleYear result format is correct', () => {
|
|
assert.match(cycleYear(), /^\d{4}\.webp$/);
|
|
});
|
|
|
|
it('imageFolder constructs correct path', () => {
|
|
assert.strictEqual(imageFolder('mm', 256, 75), 'mm-256-75');
|
|
});
|
|
|
|
it('cdnUrl returns expected jsDelivr URL', () => {
|
|
assert.strictEqual(
|
|
cdnUrl('001.webp', 'mm', 256, 75),
|
|
'https://cdn.jsdelivr.net/gh/acamarata/moon-cycle@main/mm-256-75/001.webp',
|
|
);
|
|
});
|
|
|
|
it('cycleMonth throws TypeError for invalid Date', () => {
|
|
assert.throws(() => cycleMonth(new Date('invalid')), {
|
|
name: 'TypeError',
|
|
message: 'date must be a valid Date instance',
|
|
});
|
|
});
|
|
|
|
it('cycleYear throws TypeError for invalid Date', () => {
|
|
assert.throws(() => cycleYear(new Date('invalid')), {
|
|
name: 'TypeError',
|
|
message: 'date must be a valid Date instance',
|
|
});
|
|
});
|
|
});
|