Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests to TS. #24357

Merged
merged 1 commit into from
Oct 16, 2024
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
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"endOfLine": "lf",
"tabWidth": 4,
"importOrder": [
"^[./]*/mocks",
"",
"<TYPES>^(node:)",
"",
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async function start() {
return exit(1);
}

const Controller = require('./dist/controller');
const {Controller} = require('./dist/controller');
controller = new Controller(restart, exit);

await controller.start();
Expand Down
2 changes: 0 additions & 2 deletions lib/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,3 @@ export class Controller {
}
}
}

module.exports = Controller;
9 changes: 5 additions & 4 deletions lib/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import humanizeDuration from 'humanize-duration';

import data from './data';

function pad(num: number): string {
const norm = Math.floor(Math.abs(num));
return (norm < 10 ? '0' : '') + norm;
}

// construct a local ISO8601 string (instead of UTC-based)
// Example:
// - ISO8601 (UTC) = 2019-03-01T15:32:45.941+0000
// - ISO8601 (local) = 2019-03-01T16:32:45.941+0100 (for timezone GMT+1)
function toLocalISOString(date: Date): string {
const tzOffset = -date.getTimezoneOffset();
const plusOrMinus = tzOffset >= 0 ? '+' : '-';
const pad = (num: number): string => {
const norm = Math.floor(Math.abs(num));
return (norm < 10 ? '0' : '') + norm;
};

return (
date.getFullYear() +
Expand Down
4 changes: 3 additions & 1 deletion lib/util/yaml.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'assert';
import fs from 'fs';

import equals from 'fast-deep-equal/es6';
Expand All @@ -20,7 +21,8 @@ export class YAMLFileException extends YAMLException {
function read(file: string): KeyValue {
try {
const result = yaml.load(fs.readFileSync(file, 'utf8'));
return (result as KeyValue) ?? {};
assert(result instanceof Object);
return result as KeyValue;
} catch (error) {
if (error instanceof YAMLException) {
throw new YAMLFileException(error, file);
Expand Down
584 changes: 313 additions & 271 deletions test/controller.test.js → test/controller.test.ts

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions test/data.test.js → test/data.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const logger = require('./stub/logger');
const data = require('../lib/util/data').default;
const path = require('path');
const tmp = require('tmp');
const fs = require('fs');
import path from 'path';

import tmp from 'tmp';

import data from '../lib/util/data';

describe('Data', () => {
describe('Get path', () => {
Expand Down
Loading