8000 Move unit tests to tests folder by sontx · Pull Request #2 · sontx/letrun · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Move unit tests to tests folder #2

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

Merged
merged 4 commits into from
Aug 13, 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
143 changes: 143 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# This file is inspired by https://github.com/alexkaratarakis/gitattributes
#
# Auto detect text files and perform LF normalization
# http://davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/
* text=auto

# The above will handle all files NOT found below
# These files are text and should be normalized (Convert crlf => lf)

*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf
*.coffee text
*.css text
*.cql text
*.df text
*.ejs text
*.html text
*.java text
*.js text
*.json text
*.less text
*.properties text
*.sass text
*.scss text
*.sh text eol=lf
*.sql text
*.txt text
*.ts text
*.xml text
*.yaml text
*.yml text

# Documents
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.markdown text
*.md text
*.adoc text
*.textile text
*.mustache text
*.csv text
*.tab text
*.tsv text
*.txt text
AUTHORS text
CHANGELOG text
CHANGES text
CONTRIBUTING text
COPYING text
copyright text
*COPYRIGHT* text
INSTALL text
license text
LICENSE text
NEWS text
readme text
*README* text
TODO text

# Graphics
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.tif binary
*.tiff binary
*.ico binary
# SVG treated as an asset (binary) by default. If you want to treat it as text,
# comment-out the following line and uncomment the line after.
*.svg binary
#*.svg text
*.eps binary

# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.class binary
*.jar binary
*.war binary

## LINTERS
.csslintrc text
.eslintrc text
.jscsrc text
.jshintrc text
.jshintignore text
.stylelintrc text

## CONFIGS
*.conf text
*.config text
.editorconfig text
.gitattributes text
.gitconfig text
.gitignore text
.htaccess text
*.npmignore text

## HEROKU
Procfile text
.slugignore text

## AUDIO
*.kar binary
*.m4a binary
*.mid binary
*.midi binary
*.mp3 binary
*.ogg binary
*.ra binary

## VIDEO
*.3gpp binary
*.3gp binary
*.as binary
*.asf binary
*.asx binary
*.fla binary
*.flv binary
*.m4v binary
*.mng binary
*.mov binary
*.mp4 binary
*.mpeg binary
*.mpg binary
*.swc binary
*.swf binary
*.webm binary

## ARCHIVES
*.7z binary
*.gz binary
*.rar binary
*.tar binary
*.zip binary
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/cli/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from 'jest';
import type { Config } from 'jest';

const config: Config = {
preset: 'ts-jest',
Expand All @@ -14,7 +14,9 @@ const config: Config = {
},
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
'^@src/(.*)$': '<rootDir>/src/$1',
},
testMatch: ['**/tests/**/*.test.ts'],
};

export default config;
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build": "npm run clean && node esbuild.js",
"build:prod": "npm run clean && node esbuild.js --prod",
"start": "node dist/letrun.js",
"clean": "rm -f ./dist/**",
"clean": "rm -rf ./dist/**",
"coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules npm run jest -- --coverage",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules npm run jest",
"jest": "jest"
Expand Down
15 changes: 0 additions & 15 deletions packages/cli/src/command/helper.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/cli/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { WorkflowCommand } from './workflow';
import { PluginCommand } from './plugin';
import { TaskCommand } from './task';
import { AppContext } from '@letrun/core';
export * from './helper';

export class CommandLoader {
public static async load(program: Command, context: AppContext): Promise<void> {
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/command/libs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './field-transformer';
export * from './task-helper';
export * from './utils';
24 changes: 16 additions & 8 deletions packages/cli/src/command/libs/task-helper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { AppContext, getEntryPointDir, importDefault, TaskHandler } from '@letrun/core/dist';
import { AppContext, getEntryPointDir, importDefault, TaskHandler } from '@letrun/core';
import path from 'node:path';
import { promises as fs } from 'fs';

type CustomTask = Partial<TaskHandler & { path: string; fullPath: string; group?: string }>;

export class TaskHelper {
static moduleResolver = importDefault;
static getEntryPointDir = getEntryPointDir;

static extractParentDirs(filePath: string) {
const parts = filePath.split('/');
parts.pop(); // Remove the file
Expand All @@ -27,19 +30,19 @@ export class TaskHelper {

static async loadCustomTasksFromConfig(context: AppContext) {
const tasksDir = await context.getConfigProvider().get('task.dir', 'tasks');
const pathTasksDir = path.resolve(getEntryPointDir(), tasksDir);
return await this.loadCustomTasks(pathTasksDir);
const pathTasksDir = path.resolve(this.getEntryPointDir(), tasksDir);
return await this.loadCustomTasks(pathTasksDir, context);
}

static async loadCustomTasks(tasksDir: string) {
const jsFiles = await this.getAllJsFiles(tasksDir);
static async loadCustomTasks(tasksDir: string, context: AppContext) {
const jsFiles = await this.getAllJsFiles(tasksDir, context);
const tasks: CustomTask[] = [];

for (const file of jsFiles) {
const relativePath = path.relative(tasksDir, file).replace(/\\/g, '/');
const fullPath = path.resolve(tasksDir, file);
try {
const handlerClass = await importDefault(file);
const handlerClass = await this.moduleResolver(file);
const handler = handlerClass ? new handlerClass() : null;
const isValidTask = handler?.name && handler?.handle;
tasks.push(
Expand Down Expand Up @@ -67,7 +70,7 @@ export class TaskHelper {
return tasks;
}

static async getAllJsFiles(dir: string) {
static async getAllJsFiles(dir: string, context: AppContext) {
const results: string[] = [];

const readDir = async (currentDir: string) => {
Expand All @@ -85,7 +88,12 @@ export class TaskHelper {
}
};

await readDir(dir);
try {
await readDir(dir);
} catch (e: any) {
context.getLogger().error(`Error reading directory: ${e.message}`);
return [];
}
return results;
}
}
18 changes: 18 additions & 0 deletions packages/cli/src/command/libs/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// a helper function to get the value of an option from the command line arguments
// use don't use the commander here because this happens before the commander is loaded
export function getOptionValue(shortOption: string, longOption: string) {
const args = process.argv.slice(2);

for (let i = 0; i < args.length; i++) {
if (args[i] === shortOption || args[i] === longOption) {
// If the option is found without "=", return the next argument as the value
return i + 1 < args.length ? args[i + 1] : null;
} else if (args[i]?.startsWith(shortOption + '=') || args[i]?.startsWith(longOption + '=')) {
// If the option is found with "=", split and return the value
return args[i]?.split('=')?.[1];
}
}

// Return null if the option is not specified or has no value
return null;
}
2 changes: 1 addition & 1 deletion packages/cli/src/command/plugin/list.command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbstractCommand } from '../abstract.command';
import { Command } from 'commander';
import treeify, { TreeObject } from 'treeify';
import { EMOJIS } from '../../ui';
import { EMOJIS } from '@src/ui';

export class ListCommand extends AbstractCommand {
load(program: Command): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/command/plugin/view.command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbstractCommand, AbstractOptions } from '../abstract.command';
import { Command } from 'commander';
import treeify, { TreeObject } from 'treeify';
import { EMOJIS } from '../../ui';
import { EMOJIS } from '@src/ui';

export class ViewCommand extends AbstractCommand {
load(program: Command): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/command/run.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command } from 'commander';
import { parse } from 'yaml';
import fs from 'fs';
import { DefaultRunner } from '../runner';
import { Persistence, PERSISTENCE_PLUGIN, Workflow } from '@letrun/core/dist';
import { Persistence, PERSISTENCE_PLUGIN, Workflow } from '@letrun/core';

export class RunCommand extends AbstractCommand {
load(program: Command): void {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/command/task/list.command.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AbstractCommand, AbstractOptions } from '../abstract.command';
import { Command } from 'commander';
import treeify, { TreeObject } from 'treeify';
import { SystemTaskManager } from '../../system-task';
import { EMOJIS } from '../../ui';
import { TaskHelper } from '../libs/task-helper';
import { SystemTaskManager } from '@src/system-task';
import { EMOJIS } from '@src/ui';
import { TaskHelper } from '@src/command/libs';

export class ListCommand extends AbstractCommand {
load(program: Command): void {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/command/task/run.command.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AbstractCommand, AbstractOptions } from '../abstract.command';
import { Command } from 'commander';
import { TaskHandler, WorkflowDef } from '@letrun/core';
import { DefaultRunner } from '../../runner';
import { DefaultRunner } from '@src/runner';
import fs from 'fs';
import { SystemTaskManager } from '../../system-task';
import { TaskHelper } from '../libs/task-helper';
import { SystemTaskManager } from '@src/system-task';
import { TaskHelper } from '@src/command/libs';

const SUPPORT_RUN_SYSTEM_TASKS = ['log', 'http'];

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/command/task/view.command.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AbstractCommand, AbstractOptions } from '../abstract.command';
import { Command } from 'commander';
import { asTree, TreeObject } from 'treeify';
import { EMOJIS } from '../../ui';
import { SystemTaskManager } from '../../system-task';
import { EMOJIS } from '@src/ui';
import { SystemTaskManager } from '@src/system-task';
import { TaskHandler } from '@letrun/core';
import { TaskHelper } from '../libs/task-helper';
import { TaskHelper } from '@src/command/libs';

export class ViewCommand extends AbstractCommand {
load(program: Command): void {
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/command/workflow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { ClearCommand } from './clear.command';

export class WorkflowCommand extends AbstractCommand {
load(program: Command): void {
const command = program
.command('workflow [command]')
.description('manage workflows');
const command = program.command('workflow [command]').description('manage workflows');

new ViewCommand(this.context).load(command);
new ListCommand(this.context).load(command);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/command/workflow/list.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { AbstractCommand, AbstractOptions } from '../abstract.command';
import { Command } from 'commander';
import treeify from 'treeify';
import { Persistence, PERSISTENCE_PLUGIN } from '@letrun/core';
import { FIELD_TRANSFORMERS } from './helper';
import { EMOJIS } from '../../ui';
import { FIELD_TRANSFORMERS } from '../libs';
import { EMOJIS } from '@src/ui';

export class ListCommand extends AbstractCommand {
load(program: Command): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/command/workflow/view.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { AbstractCommand, AbstractOptions } from '../abstract.command';
import { Command } from 'commander';
import fs from 'fs';
import { Container, Persistence, PERSISTENCE_PLUGIN, Workflow } from '@letrun/core';
import { FIELD_TRANSFORMERS } from './helper';
import { EMOJIS } from '../../ui';
import { FIELD_TRANSFORMERS } from '../libs';
import { EMOJIS } from '@src/ui';

export class ViewCommand extends AbstractCommand {
load(program: Command): void {
Expand Down
Loading
0