Skip to content

Commit

Permalink
fix: Refactor tests to TS (#24357)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec authored and Koenkk committed Dec 1, 2024
1 parent 2124d34 commit 6f6e7c3
Show file tree
Hide file tree
Showing 41 changed files with 4,577 additions and 4,197 deletions.
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

0 comments on commit 6f6e7c3

Please sign in to comment.