Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import * as path from 'path';
import { spawn } from 'child_process';
import { binPath } from '../utils';
import { checkFileExists } from '../utils/checkFileExists';

const defaultArgs = ['--watch'];

export const test = async (args: string[] = defaultArgs) => {
const jestBin = binPath('jest');
const configPath = path.resolve(__dirname, '../../jest.config.js');

const upperJestPath = '../../../../jest.config.js';
Copy link
Owner

@zzarcon zzarcon Mar 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it will be nice to have a util to resolve user (or upper) path

import {consumerPath} from '../utils/'

const upperJestPath = consumerPath('jest.config.js');

const defaultJestPath = '../../jest.config.js';
const pathString = checkFileExists(upperJestPath)
? upperJestPath
: defaultJestPath;
const configPath = path.resolve(__dirname, pathString);

try {
const subprocess = spawn(jestBin, ['-c', configPath, ...args], {
Expand Down
9 changes: 9 additions & 0 deletions src/utils/checkFileExists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { existsSync } from "fs";
import path from 'path';

export const checkFileExists = (resolutionPath: string) => {
if (existsSync(path.resolve(__dirname, resolutionPath))) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a similar logic in src/utils/createFile.ts I'd recommend extracting that into own util and not using the sync version:

import { promisify } from 'util';
import {exists} from 'fs'

const existFile = (path: string) => {
  return promisify(fs.exists)(path);
}

return true;
}
return false;
};