Skip to content

Commit e729bab

Browse files
committed
test: fix tests for Node.js 14-16
1 parent da5f573 commit e729bab

File tree

8 files changed

+31
-66
lines changed

8 files changed

+31
-66
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,17 @@ jobs:
9191

9292
runs-on: ${{ matrix.os }}
9393
steps:
94+
# Debug CI environment
95+
- name: Show environment (env)
96+
run: |
97+
echo "== env =="
98+
env | sort
99+
94100
- name: Checkout repository
95101
uses: actions/checkout@v4
96102
with:
97103
fetch-depth: 1
98104

99-
- name: Set up Node.js ${{ matrix.node-version }}
100-
uses: actions/setup-node@v3
101-
with:
102-
node-version: ${{ matrix.node-version }}
103-
104105
- name: Set up Node.js ${{ matrix.node-version }}
105106
uses: actions/setup-node@v4
106107
with:

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
"@types/node": "^22.15.17",
8787
"@vitest/coverage-v8": "^3.1.1",
8888
"ansis": "file:dist/node14",
89-
"color-name": "2.0.2",
9089
"css-color-names": "1.0.1",
9190
"esbuild": "0.25.2",
9291
"prettier": "3.5.3",
@@ -104,4 +103,4 @@
104103
"globby": "11.0.0"
105104
}
106105
}
107-
}
106+
}

package.test-node14.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
"node": ">=14"
3131
},
3232
"devDependencies": {
33+
"@types/node": "^14",
3334
"ansis": "file:dist/node14",
35+
"css-color-names": "1.0.1",
3436
"esbuild": "0.17.19",
3537
"rimraf": "3.0.2",
3638
"swc": "1.0.11",

test/ansi16.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { expect, describe, test } from 'vitest';
33
// import env variables to simulate 16 colors (auto detecting)
44
import './env/ansi16-colors.js';
55

6-
//import { hex, green } from '../src/index.mjs'; // for debugging only
7-
import ansis, { hex } from 'ansis';
6+
//import ansis from '../src/index.mjs'; // for debugging only
7+
import ansis from 'ansis';
88

99
describe('color level', () => {
1010
test(`ansis.level`, () => {
@@ -14,7 +14,7 @@ describe('color level', () => {
1414
});
1515

1616
test(`convert truecolor to ANSI 16 colors`, () => {
17-
const received = hex('#FFAB40')`foo`;
17+
const received = ansis.hex('#FFAB40')`foo`;
1818
const expected = 'foo';
1919
console.log('=> Should be bright yellow: ', received);
2020
expect(received).toEqual(expected);

test/ansi256.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { expect, describe, test } from 'vitest';
33
// import env variables to simulate 256 colors (auto detecting)
44
import './env/ansi256-colors.js';
55

6-
//import { Ansis, hex } from '../src/index.mjs'; // for debugging only
7-
import ansis, { Ansis, hex } from 'ansis';
6+
//import ansis, { Ansis } from '../src/index.mjs'; // for debugging only
7+
import ansis, { Ansis } from 'ansis';
88

99
describe('color level', () => {
1010
test(`ansis.level`, () => {
@@ -14,39 +14,39 @@ describe('color level', () => {
1414
});
1515

1616
test(`fallback to 256 colors`, () => {
17-
const received = hex('#00c200')`foo`;
17+
const received = ansis.hex('#00c200')`foo`;
1818
const expected = 'foo';
1919
expect(received).toEqual(expected);
2020
});
2121

2222
test(`force use truecolor`, () => {
23-
const { hex } = new Ansis(3);
23+
const ansis = new Ansis(3);
2424

25-
const received = hex('#00c200')`foo`;
25+
const received = ansis.hex('#00c200')`foo`;
2626
const expected = 'foo';
2727
expect(received).toEqual(expected);
2828
});
2929

3030
test(`force use 256 colors`, () => {
31-
const { hex } = new Ansis(2);
31+
const ansis = new Ansis(2);
3232

33-
const received = hex('#00c200')`foo`;
33+
const received = ansis.hex('#00c200')`foo`;
3434
const expected = 'foo';
3535
expect(received).toEqual(expected);
3636
});
3737

3838
test(`force use 16 colors`, () => {
39-
const { hex } = new Ansis(1);
39+
const ansis = new Ansis(1);
4040

41-
const received = hex('#00c200')`foo`;
41+
const received = ansis.hex('#00c200')`foo`;
4242
const expected = 'foo';
4343
expect(received).toEqual(expected);
4444
});
4545

4646
test(`force disable colors`, () => {
47-
const { hex } = new Ansis(0);
47+
const ansis = new Ansis(0);
4848

49-
const received = hex('#00c200')`foo`;
49+
const received = ansis.hex('#00c200')`foo`;
5050
const expected = 'foo';
5151
expect(received).toEqual(expected);
5252
});

test/named-truecolor-hex.test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { describe, test, expect, vi } from 'vitest';
33
import colorNames from 'css-color-names';
44
import ansis, { Ansis } from 'ansis';
55

6+
// truecolor level
7+
const level = 3;
8+
69
// mock ansis to ensure it always uses the required colorNames level,
710
// independent of what would be auto-detected
811
vi.mock('ansis', async () => {
912
const { Ansis } = await vi.importActual('ansis');
10-
const ansis = new Ansis(3); // force init with level 3 for truecolor
13+
const ansis = new Ansis(3); // force init with level
1114
return { default: ansis, Ansis }
1215
});
1316

@@ -35,7 +38,7 @@ describe('use colorNames name with ansis.hex()', () => {
3538
});
3639

3740
test('single extended colorNames via new instance', async () => {
38-
const ansis = new Ansis().extend(colorNames);
41+
const ansis = new Ansis(level).extend(colorNames);
3942
const received = ansis.pink('Pink');
4043
const expected = 'Pink';
4144
console.log(received);
@@ -51,15 +54,15 @@ describe('use colorNames name with ansis.hex()', () => {
5154
});
5255

5356
test('single styled extended colorNames', async () => {
54-
const ansis = new Ansis().extend(colorNames);
57+
const ansis = new Ansis(level).extend(colorNames);
5558
const received = ansis.pink.underline('Pink');
5659
const expected = 'Pink';
5760
console.log(received);
5861
expect(received).toEqual(expected);
5962
});
6063

6164
test('print all named truecolor', async () => {
62-
const ansis = new Ansis().extend(colorNames);
65+
const ansis = new Ansis(level).extend(colorNames);
6366
const names = Object.keys(colorNames);
6467
const received = names.map((name) => ansis[name](name)).join('\n');
6568

test/named-truecolor-rgb.test.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

vitest.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ export default {
1717
},
1818
},
1919

20-
// CI runners are slower, give more time and reduce threading
20+
// increase timeout for CI runners
2121
testTimeout: process.env.CI ? 20000 : 5000,
2222
hookTimeout: process.env.CI ? 10000 : 5000,
23-
threads: !process.env.CI,
24-
25-
// Less noisy logs on CI, keep logs locally
26-
silent: !!process.env.CI,
2723
},
2824
};

0 commit comments

Comments
 (0)