Skip to content

Commit 03568ce

Browse files
committed
test: add integration tests for table
1 parent 4fa9d7e commit 03568ce

File tree

5 files changed

+137
-38
lines changed

5 files changed

+137
-38
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@ jobs:
1717
needs: linux-unit-tests
1818
uses: salesforcecli/github-workflows/.github/workflows/unitTestsWindows.yml@main
1919

20+
integration:
21+
needs: linux-unit-tests
22+
strategy:
23+
matrix:
24+
os: [ubuntu-latest, windows-latest]
25+
node_version: [lts/*, latest]
26+
exclude:
27+
- os: windows-latest
28+
node_version: lts/*
29+
fail-fast: false
30+
runs-on: ${{ matrix.os }}
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-node@v4
34+
with:
35+
node-version: ${{ matrix.node_version }}
36+
cache: yarn
37+
- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
38+
- run: yarn build
39+
- run: yarn test:integration
40+
2041
external-nuts-deploy-retrieve:
2142
name: external-nuts-deploy-retrieve
2243
needs: linux-unit-tests

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"prepack": "sf-prepack",
2121
"prepare": "sf-install",
2222
"test": "wireit",
23+
"test:integration": "mocha test/**/*.integration.ts --timeout 30000",
2324
"test:only": "wireit"
2425
},
2526
"exports": {
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import { expect } from 'chai';
8+
import stripAnsi from 'strip-ansi';
9+
import { table } from '../../../src/ux/table.js';
10+
11+
/* eslint-disable camelcase */
12+
const apps = [
13+
{
14+
build_stack: {
15+
id: '123',
16+
name: 'heroku-16',
17+
},
18+
created_at: '2000-01-01T22:34:46Z',
19+
id: '123',
20+
git_url: 'https://git.heroku.com/supertable-test-1.git',
21+
name: 'supertable-test-1',
22+
owner: {
23+
email: 'example@heroku.com',
24+
id: '1',
25+
},
26+
region: { id: '123', name: 'us' },
27+
released_at: '2000-01-01T22:34:46Z',
28+
stack: {
29+
id: '123',
30+
name: 'heroku-16',
31+
},
32+
updated_at: '2000-01-01T22:34:46Z',
33+
web_url: 'https://supertable-test-1.herokuapp.com/',
34+
},
35+
{
36+
build_stack: {
37+
id: '321',
38+
name: 'heroku-16',
39+
},
40+
created_at: '2000-01-01T22:34:46Z',
41+
id: '321',
42+
git_url: 'https://git.heroku.com/phishing-demo.git',
43+
name: 'supertable-test-2',
44+
owner: {
45+
email: 'example@heroku.com',
46+
id: '1',
47+
},
48+
region: { id: '321', name: 'us' },
49+
released_at: '2000-01-01T22:34:46Z',
50+
stack: {
51+
id: '321',
52+
name: 'heroku-16',
53+
},
54+
updated_at: '2000-01-01T22:34:46Z',
55+
web_url: 'https://supertable-test-2.herokuapp.com/',
56+
},
57+
];
58+
59+
const columns = {
60+
id: { header: 'ID' },
61+
name: {},
62+
web_url: { extended: true },
63+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
64+
stack: { extended: true, get: (r: any) => r.stack?.name },
65+
};
66+
67+
const ws = ' ';
68+
69+
describe('table', () => {
70+
let output = '';
71+
function printLine(line: string) {
72+
output += stripAnsi(line) + '\n';
73+
}
74+
75+
afterEach(() => {
76+
output = '';
77+
});
78+
79+
// This can't be in the unit tests since wireit changes process.stdout.isTTY, which alters the behavior of table
80+
it('should not truncate in TTY env', () => {
81+
const three = { ...apps[0], id: '0'.repeat(80), name: 'supertable-test-3' };
82+
table([...apps, three], columns, { filter: 'id=0', printLine, truncate: false });
83+
expect(output).to.equal(` ID${ws.padEnd(78)} Name${ws.padEnd(14)}
84+
${''.padEnd(three.id.length, '─')} ─────────────────${ws}
85+
${three.id} supertable-test-3${ws}\n`);
86+
});
87+
88+
it('does not exceed stack depth on very tall tables', () => {
89+
const data = Array.from({ length: 150_000 }).fill({ id: '123', name: 'foo', value: 'bar' }) as Array<
90+
Record<string, unknown>
91+
>;
92+
const tallColumns = {
93+
id: { header: 'ID' },
94+
name: {},
95+
value: { header: 'TEST' },
96+
};
97+
98+
table(data, tallColumns, { printLine });
99+
expect(output).to.include('ID');
100+
});
101+
102+
// skip because it's too slow
103+
it.skip('does not exceed stack depth on very tall, wide tables', () => {
104+
const columnsLength = 100;
105+
const row = Object.fromEntries(Array.from({ length: columnsLength }).map((_, i) => [`col${i}`, 'foo']));
106+
const data = Array.from({ length: 150_000 }).fill(row) as Array<Record<string, unknown>>;
107+
const bigColumns = Object.fromEntries(
108+
Array.from({ length: columnsLength }).map((_, i) => [`col${i}`, { header: `col${i}`.toUpperCase() }])
109+
);
110+
111+
table(data, bigColumns, { printLine });
112+
expect(output).to.include('COL1');
113+
});
114+
});

test/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "@salesforce/dev-config/tsconfig-test-strict-esm",
3-
"include": ["unit/**/*.ts", "../node_modules/@types/**/*.d.ts"],
3+
"include": ["unit/**/*.ts", "../node_modules/@types/**/*.d.ts", "integration/**/*.ts"],
44
"compilerOptions": {
55
"noEmit": true,
66
"skipLibCheck": true

test/unit/ux/table.test.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,6 @@ describe('table', () => {
233233
─── ─────────────────${ws}
234234
123 supertable-test-1${ws}\n`);
235235
});
236-
237-
// This test doesn't work because tests have process.stdout.isTTY=undefined when wireit runs the tests
238-
// `yarn mocha test` works fine since process.stdout.isTTY=true
239-
it.skip('should not truncate', () => {
240-
const three = { ...apps[0], id: '0'.repeat(80), name: 'supertable-test-3' };
241-
table([...apps, three], columns, { filter: 'id=0', printLine, truncate: false });
242-
expect(output).to.equal(` ID${ws.padEnd(78)} Name${ws.padEnd(14)}
243-
${''.padEnd(three.id.length, '─')} ─────────────────${ws}
244-
${three.id} supertable-test-3${ws}\n`);
245-
});
246236
});
247237

248238
describe('edge cases', () => {
@@ -272,32 +262,5 @@ describe('table', () => {
272262
321 supertable-test-2${ws}
273263
123 supertable-test-1${ws}\n`);
274264
});
275-
276-
it('does not exceed stack depth on very tall tables', () => {
277-
const data = Array.from({ length: 150_000 }).fill({ id: '123', name: 'foo', value: 'bar' }) as Array<
278-
Record<string, unknown>
279-
>;
280-
const tallColumns = {
281-
id: { header: 'ID' },
282-
name: {},
283-
value: { header: 'TEST' },
284-
};
285-
286-
table(data, tallColumns, { printLine });
287-
expect(output).to.include('ID');
288-
});
289-
290-
// Skip because it takes too long
291-
it.skip('does not exceed stack depth on very tall, wide tables', () => {
292-
const columnsLength = 100;
293-
const row = Object.fromEntries(Array.from({ length: columnsLength }).map((_, i) => [`col${i}`, 'foo']));
294-
const data = Array.from({ length: 150_000 }).fill(row) as Array<Record<string, unknown>>;
295-
const bigColumns = Object.fromEntries(
296-
Array.from({ length: columnsLength }).map((_, i) => [`col${i}`, { header: `col${i}`.toUpperCase() }])
297-
);
298-
299-
table(data, bigColumns, { printLine });
300-
expect(output).to.include('COL1');
301-
});
302265
});
303266
});

0 commit comments

Comments
 (0)