Skip to content

Commit

Permalink
chore: re-write some files to typescript (#487)
Browse files Browse the repository at this point in the history
* chore: re-write test-statuses to typescript

* chore: re-write plugin-utils to typescript

* chore: rename server utils and constants paths to typescript

* chore: rename diff-modes and view-modes to typescript

* chore: re-write view-modes and diff-modes to typescript

* chore: re-write server-utils to typescript

* chore: re-generate package-lock
  • Loading branch information
shadowusr authored Aug 11, 2023
1 parent 0791d99 commit 9b58bbb
Show file tree
Hide file tree
Showing 56 changed files with 6,422 additions and 5,440 deletions.
1 change: 1 addition & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

module.exports = {
extension: ["js", "jsx", "ts", "tsx"],
recursive: true,
require: ["./test/ts-node", "./test/setup", "./test/assert-ext", "jsdom-global/register"],
};
4 changes: 2 additions & 2 deletions lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const chalk = require('chalk');

const {logger} = require('../common-utils');
const {config: configDefaults} = require('../constants/defaults');
const diffModes = require('../constants/diff-modes');
const {DiffModes} = require('../constants/diff-modes');
const saveFormats = require('../constants/save-formats');
const {assertCustomGui} = require('./custom-gui-asserts');

Expand Down Expand Up @@ -120,7 +120,7 @@ const assertDiffMode = (diffMode) => {
throw new Error(`"diffMode" option must be a string, but got ${typeof diffMode}`);
}

const availableValues = Object.values(diffModes).map(v => v.id);
const availableValues = Object.values(DiffModes).map(v => v.id);

if (!availableValues.includes(diffMode)) {
throw new Error(`"diffMode" must be one of "${availableValues.join('", "')}", but got "${diffMode}"`);
Expand Down
8 changes: 4 additions & 4 deletions lib/constants/defaults.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const diffModes = require('./diff-modes');
const viewModes = require('./view-modes');
const {DiffModes} = require('./diff-modes');
const {ViewMode} = require('./view-modes');

module.exports = {
CIRCLE_RADIUS: 150,
config: {
saveErrorDetails: false,
commandsWithShortHistory: [],
defaultView: viewModes.ALL,
diffMode: diffModes.THREE_UP.id,
defaultView: ViewMode.ALL,
diffMode: DiffModes.THREE_UP.id,
baseHost: '',
lazyLoadOffset: null,
errorPatterns: [],
Expand Down
10 changes: 8 additions & 2 deletions lib/constants/diff-modes.js → lib/constants/diff-modes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import {ValueOf} from 'type-fest';

export const DiffModes = {
THREE_UP: {
id: '3-up',
title: '3-up',
Expand Down Expand Up @@ -34,4 +36,8 @@ module.exports = {
title: 'Onion skin',
description: 'move slider'
}
};
} as const;

export type DiffModes = typeof DiffModes;

export type DiffMode = ValueOf<DiffModes>;
4 changes: 4 additions & 0 deletions lib/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './diff-modes';
export * from './paths';
export * from './test-statuses';
export * from './view-modes';
6 changes: 0 additions & 6 deletions lib/constants/paths.js

This file was deleted.

2 changes: 2 additions & 0 deletions lib/constants/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const IMAGES_PATH = 'images';
export const ERROR_DETAILS_PATH = 'error-details';
12 changes: 0 additions & 12 deletions lib/constants/test-statuses.js

This file was deleted.

19 changes: 19 additions & 0 deletions lib/constants/test-statuses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export enum TestStatus {
IDLE = 'idle',
QUEUED = 'queued',
RUNNING = 'running',
SUCCESS = 'success',
FAIL = 'fail',
ERROR = 'error',
SKIPPED = 'skipped',
UPDATED = 'updated',
}

export const IDLE = TestStatus.IDLE;
export const QUEUED = TestStatus.QUEUED;
export const RUNNING = TestStatus.RUNNING;
export const SUCCESS = TestStatus.SUCCESS;
export const FAIL = TestStatus.FAIL;
export const ERROR = TestStatus.ERROR;
export const SKIPPED = TestStatus.SKIPPED;
export const UPDATED = TestStatus.UPDATED;
9 changes: 0 additions & 9 deletions lib/constants/view-modes.js

This file was deleted.

7 changes: 7 additions & 0 deletions lib/constants/view-modes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum ViewMode {
ALL = 'all',
PASSED = 'passed',
FAILED = 'failed',
RETRIED = 'retried',
SKIPPED = 'skipped',
}
4 changes: 3 additions & 1 deletion lib/gui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import chalk from 'chalk';
import opener from 'opener';
import server from './server';
import {logger} from '../common-utils';
import {logError} from '../server-utils';
import * as utils from '../server-utils';

const {logError} = utils;

interface ServerArgs {
paths: string[];
Expand Down
2 changes: 1 addition & 1 deletion lib/gui/tool-runner/report-subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const os = require('os');
const PQueue = require('p-queue');
const clientEvents = require('../constants/client-events');
const {RUNNING} = require('../../constants/test-statuses');
const {getSuitePath} = require('../../plugin-utils').getHermioneUtils();
const {getSuitePath} = require('../../plugin-utils');
const createWorkers = require('../../workers/create-workers');
const {logError} = require('../../server-utils');

Expand Down
9 changes: 0 additions & 9 deletions lib/plugin-utils.js

This file was deleted.

7 changes: 7 additions & 0 deletions lib/plugin-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Suite} from './types';

export const getSuitePath = (suite: Suite): string[] => {
return suite.root ?
[] :
([] as string[]).concat(getSuitePath(suite.parent as Suite)).concat(suite.title);
};
Loading

0 comments on commit 9b58bbb

Please sign in to comment.