Skip to content

Commit 34aa49f

Browse files
committed
test message
1 parent 5744033 commit 34aa49f

13 files changed

Lines changed: 697 additions & 10 deletions

File tree

.github/workflows/hourly-tests.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
# packages on multiple Node.js versions (18.x, 20.x, 22.x, 24.x).
77
#
88
# It performs:
9-
# - Unit tests on all supported Node.js versions
9+
# - JavaScript unit tests
10+
# - TypeScript import and type tests
11+
# - Tests run on all supported Node.js versions
1012
#
1113
# The workflow runs:
1214
# - Hourly (via cron)
@@ -48,5 +50,5 @@ jobs:
4850
- name: Install dependencies
4951
run: yarn install
5052

51-
- name: Run unit tests
52-
run: yarn test:unit
53+
- name: Run JavaScript and TypeScript tests
54+
run: yarn test

.github/workflows/node12-tests.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# =======================================================================
2+
# Node.js 12 Compatibility Tests Workflow
3+
# =======================================================================
4+
#
5+
# This workflow specifically tests the compatibility of console-table-printer
6+
# and simple-wcswidth packages with Node.js 12.x.
7+
#
8+
# Since Jest 30.x is not compatible with Node.js 12.x, this workflow:
9+
# 1. Removes Jest 30.x
10+
# 2. Installs Jest 27.x which is compatible with Node.js 12
11+
# 3. Runs the unit tests
12+
#
13+
# This ensures that users on Node.js 12.x can still use these libraries
14+
# even though the latest testing tools may not support this version.
15+
#
16+
# The workflow runs:
17+
# - Hourly (via cron)
18+
# - On push to main branch
19+
# - Manually via workflow_dispatch
20+
#
21+
# Test results are uploaded as artifacts and stored for 7 days.
22+
# =======================================================================
23+
24+
name: Node.js 12 Tests
25+
26+
on:
27+
schedule:
28+
# Run every hour
29+
- cron: '0 * * * *'
30+
# Also run on push to main branch
31+
push:
32+
branches: [ main ]
33+
# Allow manual triggering
34+
workflow_dispatch:
35+
36+
jobs:
37+
node12-tests:
38+
name: Node.js 12.x Tests
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Setup Node.js 12.x
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version: '12.x'
49+
cache: 'yarn'
50+
51+
- name: Install dependencies
52+
run: |
53+
# Remove incompatible Jest 30.x
54+
yarn remove jest
55+
# Install Jest 27.x which is compatible with Node.js 12
56+
yarn add jest@27 --dev
57+
58+
- name: Run unit tests
59+
run: yarn test:unit
60+
61+
- name: Upload test results
62+
if: always()
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: node12-test-results
66+
path: |
67+
junit.xml
68+
retention-days: 7

.github/workflows/node14-tests.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# =======================================================================
2+
# Node.js 14 Compatibility Tests Workflow
3+
# =======================================================================
4+
#
5+
# This workflow specifically tests the compatibility of console-table-printer
6+
# and simple-wcswidth packages with Node.js 14.x.
7+
#
8+
# Since Jest 30.x is not compatible with Node.js 14.x, this workflow:
9+
# 1. Removes Jest 30.x
10+
# 2. Installs Jest 29.x which is compatible with Node.js 14
11+
# 3. Runs the unit tests
12+
#
13+
# This ensures that users on Node.js 14.x can still use these libraries
14+
# even though the latest testing tools may not support this version.
15+
#
16+
# The workflow runs:
17+
# - Hourly (via cron)
18+
# - On push to main branch
19+
# - Manually via workflow_dispatch
20+
#
21+
# Test results are uploaded as artifacts and stored for 7 days.
22+
# =======================================================================
23+
24+
name: Node.js 14 Tests
25+
26+
on:
27+
schedule:
28+
# Run every hour
29+
- cron: '0 * * * *'
30+
# Also run on push to main branch
31+
push:
32+
branches: [ main ]
33+
# Allow manual triggering
34+
workflow_dispatch:
35+
36+
jobs:
37+
node14-tests:
38+
name: Node.js 14.x Tests
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Setup Node.js 14.x
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version: '14.x'
49+
cache: 'yarn'
50+
51+
- name: Install dependencies
52+
run: |
53+
# Remove incompatible Jest 30.x
54+
yarn remove jest
55+
# Install Jest 29.x which is compatible with Node.js 14
56+
yarn add jest@29 --dev
57+
58+
- name: Run unit tests
59+
run: yarn test:unit
60+
61+
- name: Upload test results
62+
if: always()
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: node14-test-results
66+
path: |
67+
junit.xml
68+
retention-days: 7
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: TypeScript Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '0 * * * *' # Run every hour
10+
workflow_dispatch: # Allow manual triggering
11+
12+
jobs:
13+
typescript-tests:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [16.x, 18.x, 20.x, 22.x]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
28+
- name: Install dependencies
29+
run: yarn install --frozen-lockfile
30+
31+
- name: Install TypeScript packages
32+
run: yarn add --dev typescript ts-jest @types/jest
33+
34+
- name: Install console-table-printer and simple-wcswidth
35+
run: yarn add console-table-printer simple-wcswidth
36+
37+
- name: Run TypeScript tests
38+
run: npx jest tests/typescript

jest.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = {
22
testEnvironment: 'node',
3-
testMatch: ['**/tests/**/*.test.js'],
3+
testMatch: ['**/tests/**/*.test.js', '**/tests/**/*.test.ts'],
44
testPathIgnorePatterns: ['/node_modules/', '/tests/website/'],
55
verbose: true,
6+
transform: {
7+
'^.+\\.tsx?$': 'ts-jest',
8+
},
69
};

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
},
2929
"devDependencies": {
3030
"@playwright/test": "^1.53.1",
31-
"playwright": "^1.53.1"
31+
"@types/jest": "^30.0.0",
32+
"playwright": "^1.53.1",
33+
"ts-jest": "^29.4.0",
34+
"typescript": "^5.8.3"
3235
}
3336
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { Table } from 'console-table-printer';
2+
3+
// Define interfaces for type checking
4+
interface Person {
5+
name: string;
6+
age: number;
7+
country: string;
8+
salary?: number;
9+
}
10+
11+
interface TableWithStyles {
12+
addRow: (row: Record<string, any>) => void;
13+
addRows: (rows: Record<string, any>[]) => void;
14+
printTable: () => void;
15+
addRowIndexColumn: () => void;
16+
sortBy: (columnName: string) => void;
17+
}
18+
19+
describe('Console Table Printer - TypeScript Advanced Tests', () => {
20+
test('should be properly typed and importable with advanced features', () => {
21+
// Verify that the Table class exists and is a constructor
22+
expect(typeof Table).toBe('function');
23+
24+
// Create a table with TypeScript type checking
25+
const p = new Table();
26+
expect(p).toBeInstanceOf(Table);
27+
});
28+
29+
test('should create a table with rows', () => {
30+
const p = new Table();
31+
32+
// Add rows
33+
p.addRows([
34+
{ name: 'Alice', age: 25, country: 'USA' },
35+
{ name: 'Bob', age: 30, country: 'Canada' },
36+
{ name: 'Charlie', age: 35, country: 'UK' }
37+
]);
38+
39+
// The test passes if no TypeScript errors occur
40+
expect(true).toBe(true);
41+
});
42+
43+
test('should add rows with TypeScript type checking', () => {
44+
const p = new Table();
45+
46+
// Add rows with TypeScript type checking
47+
const people: Person[] = [
48+
{ name: 'Charlie', age: 35, country: 'UK' },
49+
{ name: 'Alice', age: 25, country: 'USA' },
50+
{ name: 'Bob', age: 30, country: 'Canada' }
51+
];
52+
53+
p.addRows(people);
54+
55+
// The test passes if no TypeScript errors occur
56+
expect(true).toBe(true);
57+
});
58+
59+
test('should create a table with rows containing salary information', () => {
60+
const p = new Table();
61+
62+
// Add rows with TypeScript type checking
63+
const people: Person[] = [
64+
{ name: 'Alice', age: 25, country: 'USA', salary: 100000 },
65+
{ name: 'Bob', age: 30, country: 'Canada', salary: 120000 },
66+
{ name: 'Charlie', age: 35, country: 'UK', salary: 90000 }
67+
];
68+
69+
p.addRows(people);
70+
71+
// The test passes if no TypeScript errors occur
72+
expect(true).toBe(true);
73+
});
74+
75+
test('should create a table with custom columns', () => {
76+
// Create a table with custom columns
77+
const p = new Table({
78+
columns: [
79+
{ name: 'name', alignment: 'left' },
80+
{ name: 'age', alignment: 'right' },
81+
{ name: 'country', alignment: 'left' }
82+
]
83+
});
84+
85+
// Add rows with TypeScript type checking
86+
const people: Person[] = [
87+
{ name: 'Alice', age: 25, country: 'USA' },
88+
{ name: 'Bob', age: 30, country: 'Canada' },
89+
{ name: 'Charlie', age: 35, country: 'UK' }
90+
];
91+
92+
p.addRows(people);
93+
94+
// The test passes if no TypeScript errors occur
95+
expect(true).toBe(true);
96+
});
97+
98+
test('should handle nested objects in rows', () => {
99+
interface NestedPerson {
100+
name: string;
101+
details: {
102+
age: number;
103+
country: string;
104+
};
105+
}
106+
107+
const p = new Table();
108+
109+
// Add rows with nested objects
110+
const people: NestedPerson[] = [
111+
{ name: 'Alice', details: { age: 25, country: 'USA' } },
112+
{ name: 'Bob', details: { age: 30, country: 'Canada' } },
113+
{ name: 'Charlie', details: { age: 35, country: 'UK' } }
114+
];
115+
116+
// Add rows using flat structure for display
117+
p.addRows([
118+
{ name: people[0].name, age: people[0].details.age, country: people[0].details.country },
119+
{ name: people[1].name, age: people[1].details.age, country: people[1].details.country },
120+
{ name: people[2].name, age: people[2].details.age, country: people[2].details.country }
121+
]);
122+
123+
// The test passes if no TypeScript errors occur
124+
expect(true).toBe(true);
125+
});
126+
});

0 commit comments

Comments
 (0)