-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add util to load worker conf based on env
- Loading branch information
Showing
2 changed files
with
25 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as path from 'path'; | ||
|
||
interface WorkerConfig { | ||
workerPath: string; | ||
execArgv: string[]; | ||
} | ||
|
||
// Since node workers do not support ts out of the box, we need to specify the JS file for the app, but TS file for the tests. | ||
|
||
export const getWorkerConfig = (fileName: string): WorkerConfig => { | ||
const isTestEnvironment: boolean = process.env.NODE_ENV === 'test'; | ||
const workerPath: WorkerConfig['workerPath'] = isTestEnvironment | ||
? path.resolve(__dirname, `./workers/${fileName}.ts`) | ||
: path.resolve(__dirname, `./workers/${fileName}.js`); | ||
|
||
const execArgv: WorkerConfig['execArgv'] = isTestEnvironment | ||
? ['-r', 'ts-node/register'] | ||
: []; | ||
|
||
return { workerPath, execArgv }; | ||
}; |