Skip to content

Commit d4efb3e

Browse files
committed
Fixed tests, tested on WSL and windows, confirmed working.
1 parent d66ef04 commit d4efb3e

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/bin/typescript-demo-lib.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import testUptNative from '../lib/test-utp-native';
1010

1111
async function main(argv = process.argv): Promise<number> {
1212
// Print out command-line arguments
13-
const argArray = argv.slice(2);
14-
const args = argArray.toString();
15-
process.stdout.write('[' + args + ']\n');
13+
argv = argv.slice(2); // Removing prepended file paths.
14+
process.stdout.write('[' + argv.slice(0, 2).toString() + ']\n');
1615

1716
// Create a new Library with the value someParam = 'new library'
1817
// And print it out
@@ -23,12 +22,13 @@ async function main(argv = process.argv): Promise<number> {
2322
process.stdout.write(uuidv4() + '\n');
2423

2524
// Add the first two command-line args and print the result
26-
const nums = new NumPair(parseInt(argArray[0]), parseInt(argArray[1]));
25+
const nums = new NumPair(parseInt(argv[0]), parseInt(argv[1]));
2726
const sum = nums.num1 + nums.num2;
2827
process.stdout.write(nums.num1 + ' + ' + nums.num2 + ' = ' + sum + '\n');
2928

3029
// Testing native modules.
31-
await testLevel(argv[0]);
30+
const dir = argv[2] ?? '.';
31+
await testLevel(dir);
3232
await testWorkers();
3333
await testUptNative();
3434

tests/bin/typescript-demo-lib.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ describe('main', () => {
2323
// jest can also "spy on" the console object
2424
// and then you can test on stdout
2525
const mockLog = mockProcessStdout();
26-
expect(await main([dataDir, '', '1', '2'])).toEqual(0);
26+
expect(await main(['', '', '1', '2', dataDir])).toEqual(0);
2727
mockLog.mockRestore();
2828
});
2929
test('no input', async () => {
3030
const mockLog = mockProcessStdout();
31-
await main([dataDir, '']);
31+
await main([]);
3232
const tmpMockLog = mockLog.mock.calls.join('');
3333
expect(tmpMockLog).toContain('[]\n');
3434
expect(tmpMockLog).toContain('new library\n');
@@ -38,7 +38,7 @@ describe('main', () => {
3838
}, 20000);
3939
test('adds 0 + 0', async () => {
4040
const mockLog = mockProcessStdout();
41-
await main([dataDir, '', '0', '0']);
41+
await main(['', '', '0', '0', dataDir]);
4242
const tmpMockLog = mockLog.mock.calls.join('');
4343
expect(tmpMockLog).toContain('[0,0]\n');
4444
expect(tmpMockLog).toContain('new library\n');
@@ -48,7 +48,7 @@ describe('main', () => {
4848
});
4949
test('adds 0 + 1', async () => {
5050
const mockLog = mockProcessStdout();
51-
await main([dataDir, '', '0', '1']);
51+
await main(['', '', '0', '1', dataDir]);
5252
const tmpMockLog = mockLog.mock.calls.join('');
5353
expect(tmpMockLog).toContain('[0,1]\n');
5454
expect(tmpMockLog).toContain('new library\n');
@@ -58,7 +58,7 @@ describe('main', () => {
5858
});
5959
test('adds 1 + 0', async () => {
6060
const mockLog = mockProcessStdout();
61-
await main([dataDir, '', '1', '0']);
61+
await main(['', '', '1', '0', dataDir]);
6262
const tmpMockLog = mockLog.mock.calls.join('');
6363
expect(tmpMockLog).toContain('[1,0]\n');
6464
expect(tmpMockLog).toContain('new library\n');
@@ -68,7 +68,7 @@ describe('main', () => {
6868
});
6969
test('adds 7657 + 238947', async () => {
7070
const mockLog = mockProcessStdout();
71-
await main([dataDir, '', '7657', '238947']);
71+
await main(['', '', '7657', '238947', dataDir]);
7272
const tmpMockLog = mockLog.mock.calls.join('');
7373
expect(tmpMockLog).toContain('[7657,238947]\n');
7474
expect(tmpMockLog).toContain('new library\n');
@@ -78,23 +78,23 @@ describe('main', () => {
7878
});
7979
test('level should work.', async () => {
8080
const mockLog = mockProcessStdout();
81-
await main([dataDir]);
81+
await main(['', '', '', '', dataDir]);
8282
const tmpMockLog = mockLog.mock.calls.join('');
8383
expect(tmpMockLog).toContain('lets test some levelDB');
8484
expect(tmpMockLog).toContain('hello Level!');
8585
mockLog.mockRestore();
8686
});
8787
test('Worker threads should work.', async () => {
8888
const mockLog = mockProcessStdout();
89-
await main([dataDir]);
89+
await main(['', '', '', '', dataDir]);
9090
const tmpMockLog = mockLog.mock.calls.join('');
9191
expect(tmpMockLog).toContain('Lets test workers.');
9292
expect(tmpMockLog).toContain('Hello Worker!');
9393
mockLog.mockRestore();
9494
});
9595
test('utp-native should work.', async () => {
9696
const mockLog = mockProcessStdout();
97-
await main([dataDir]);
97+
await main(['', '', '', '', dataDir]);
9898
const tmpMockLog = mockLog.mock.calls.join('');
9999
expect(tmpMockLog).toContain('Lets test utp-native.');
100100
expect(tmpMockLog).toContain('hello UTP!!');

0 commit comments

Comments
 (0)