Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/auto-merge/src/AutoMerge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ describe('AutoMerge', () => {
});

nock(autoMerge['baseURL']!)
.post(/^\/repos\/.+?\/.+?\/pulls\/\d+(\/(reviews|merge))?\/?$/)
.post(/^\/repos\/.+?\/.+?\/pulls\/\d+(\/reviews)?\/?$/)
.reply(HTTP_STATUS.OK, {data: 'not-used'})
.persist();

nock(autoMerge['baseURL']!)
.put(/^\/repos\/.+?\/.+?\/pulls\/\d+(\/merge)?\/?$/)
.reply(HTTP_STATUS.OK, {data: 'not-used'})
.persist();

Expand Down
72 changes: 13 additions & 59 deletions packages/double-linked-list/src/DoubleLinkedList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,56 +35,25 @@ describe('ListElement', () => {

test(`doesn't connect an invalid next element`, () => {
const element1 = new ListElement('one');

try {
element1.setNext('error' as any);
assert.fail();
} catch (error) {
expect((error as Error).message).toBe('Invalid next element.');
}
// @ts-expect-error test invalid value
expect(() => element1.setNext('error')).toThrowError('Invalid next element.');
});

test(`doesn't connect an invalid previous element`, () => {
const element1 = new ListElement('one');

try {
element1.setPrev('error' as any);
assert.fail();
} catch (error) {
expect((error as Error).message).toBe('Invalid previous element.');
}
// @ts-expect-error test invalid value
expect(() => element1.setPrev('error')).toThrowError('Invalid previous element.');
});

test(`doesn't accept an invalid value`, () => {
try {
new (ListElement as any)();
assert.fail();
} catch (error) {
expect((error as Error).message).toBe('Invalid value.');
}

try {
new ListElement(null);
assert.fail();
} catch (error) {
expect((error as Error).message).toBe('Invalid value.');
}
// @ts-expect-error test invalid value
expect(() => new ListElement()).toThrowError('Invalid value.');
expect(() => new ListElement(null)).toThrowError('Invalid value.');

const element1 = new ListElement('');

try {
element1.setValue(undefined as any);
assert.fail();
} catch (error) {
expect((error as Error).message).toBe('Invalid value.');
}

try {
element1.setValue(null);
assert.fail();
} catch (error) {
expect((error as Error).message).toBe('Invalid value.');
}
// @ts-expect-error test invalid value
expect(() => element1.setValue(undefined)).toThrowError('Invalid value.');
expect(() => element1.setValue(null)).toThrowError('Invalid value.');
});
});

Expand Down Expand Up @@ -133,28 +102,13 @@ describe('LinkedList', () => {
});

test(`doesn't go outside the list's bounds`, () => {
try {
list.get(0);
assert.fail();
} catch (error) {
expect((error as Error).message).toBe('Index 0 is out of bounds.');
}
expect(() => list.get(0)).toThrowError('Index 0 is out of bounds.');

list.add('zero');

try {
list.get(2);
assert.fail();
} catch (error) {
expect((error as Error).message).toBe('Index 2 is out of bounds.');
}
expect(() => list.get(2)).toThrowError('Index 2 is out of bounds.');

try {
list.remove(2);
assert.fail();
} catch (error) {
expect((error as Error).message).toBe('Index 2 is out of bounds.');
}
expect(() => list.remove(2)).toThrowError('Index 2 is out of bounds.');
});

test(`gets the list's head and tail`, () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jszip-cli/src/JSZipCLI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('JSZipCLI', () => {
try {
await fs.mkdir(tempDir);
} catch {
// no-op
// directory already exists
}
});
afterAll(() => fs.rm(tempDir, {force: true, recursive: true}));
Expand Down
51 changes: 16 additions & 35 deletions packages/mock-udp/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ describe('mock-udp.clean', () => {
mockudp.clean();
const client = dgram.createSocket('udp4');
range.forEach(index => {
try {
// eslint-disable-next-line no-magic-numbers
client.send(buffer, 0, buffer.length, 1000 + index, 'localhost');
assert.fail();
} catch {
// no-op
}
// eslint-disable-next-line no-magic-numbers
expect(() => client.send(buffer, 0, buffer.length, 1000 + index, 'localhost')).toThrowError();
});
});
});
Expand Down Expand Up @@ -106,6 +101,7 @@ describe('mock-udp.overriddenSocketSend', () => {
const scope1 = mockudp.add('localhost:1000');
const scope2 = mockudp.add('localhost:1000');
const client = dgram.createSocket('udp4');

// eslint-disable-next-line no-magic-numbers
client.send(buffer, 0, buffer.length, 1000, 'localhost', () => {
scope1.done();
Expand All @@ -119,56 +115,41 @@ describe('mock-udp.overriddenSocketSend', () => {
return new Promise(done => {
const scope = mockudp.add('localhost:1000');
const client = dgram.createSocket('udp4');

// eslint-disable-next-line no-magic-numbers
client.send(buffer, 0, buffer.length, 1000, 'localhost', () => {
scope.done();
try {
// eslint-disable-next-line no-magic-numbers
client.send(buffer, 0, buffer.length, 1000, 'localhost');
assert.fail();
} catch {
done(void 0);
}
// eslint-disable-next-line no-magic-numbers
expect(() => client.send(buffer, 0, buffer.length, 1000, 'localhost')).toThrowError();
done(void 0);
});
});
});

test('should throw an error if offset is equal to the length of the buffer', () => {
const scope = mockudp.add('localhost:1000');
const client = dgram.createSocket('udp4');
try {
// eslint-disable-next-line no-magic-numbers
client.send(buffer, buffer.length, buffer.length, 1000, 'localhost');
assert.fail();
} catch {
// no-op
}

// eslint-disable-next-line no-magic-numbers
expect(() => client.send(buffer, buffer.length, buffer.length, 1000, 'localhost')).toThrowError();
expect(scope.done()).toBe(false);
});

test('should throw an error if offset is greater than the length of the buffer', () => {
const scope = mockudp.add('localhost:1000');
const client = dgram.createSocket('udp4');
try {
// eslint-disable-next-line no-magic-numbers
client.send(buffer, buffer.length + 1, buffer.length, 1000, 'localhost');
assert.fail();
} catch {
// no-op
}

// eslint-disable-next-line no-magic-numbers
expect(() => client.send(buffer, buffer.length + 1, buffer.length, 1000, 'localhost')).toThrowError();
expect(scope.done()).toBe(false);
});

test('should throw an error if the length is greater than the length of the buffer', () => {
const scope = mockudp.add('localhost:1000');
const client = dgram.createSocket('udp4');
try {
// eslint-disable-next-line no-magic-numbers
client.send(buffer, 0, buffer.length + 1, 1000, 'localhost');
assert.fail();
} catch {
// no-op
}

// eslint-disable-next-line no-magic-numbers
expect(() => client.send(buffer, 0, buffer.length + 1, 1000, 'localhost')).toThrowError();
expect(scope.done()).toBe(false);
});
});
15 changes: 5 additions & 10 deletions packages/ntpclient/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,10 @@ describe.skip('NTP', () => {
);

it("doesn't work with an invalid NTP server", async () => {
try {
const ntpClient = new NTPClient({
replyTimeout: SECOND_IN_MILLIS,
server: 'google.com',
});
await ntpClient.getNetworkTime();
assert.fail();
} catch (error) {
expect((error as Error).message).toContain('Timeout');
}
const ntpClient = new NTPClient({
replyTimeout: SECOND_IN_MILLIS,
server: 'google.com',
});
await expect(ntpClient.getNetworkTime()).rejects.toThrowError(/Timeout/);
});
});
7 changes: 1 addition & 6 deletions packages/scrabble-cheater/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ describe('ScrabbleCheater', () => {

test(`Doesn't accept an empty file`, async () => {
const sc = new ScrabbleCheater(emptyList);
try {
await sc.start();
assert.fail();
} catch {
// nothing to do
}
await expect(sc.start()).rejects.toThrowError();
});
});