diff --git a/standalone/standalone/src/Runner.ts b/standalone/standalone/src/Runner.ts index de96ff8f..a05969ea 100644 --- a/standalone/standalone/src/Runner.ts +++ b/standalone/standalone/src/Runner.ts @@ -33,6 +33,7 @@ export interface RunnerOptions { */ innerObjects?: Record; env?: string; + name?: string; innerObjectHandlers?: Record; } @@ -41,6 +42,7 @@ export class Runner { readonly moduleReferences: readonly ModuleReference[]; readonly moduleConfigs: Record; readonly env?: string; + readonly name?: string; private loadUnitLoader: EggModuleLoader; private runnerProto: EggPrototype; private configSourceEggPrototypeHook: ConfigSourceLoadUnitHook; @@ -59,6 +61,7 @@ export class Runner { constructor(cwd: string, options?: RunnerOptions) { this.cwd = cwd; this.env = options?.env; + this.name = options?.name; this.moduleReferences = ModuleConfigUtil.readModuleReference(this.cwd); this.moduleConfigs = {}; this.innerObjects = { @@ -70,6 +73,8 @@ export class Runner { const runtimeConfig: Partial = { baseDir: this.cwd, + name: this.name, + env: this.env, }; // Inject runtimeConfig this.innerObjects.runtimeConfig = [{ diff --git a/standalone/standalone/test/index.test.ts b/standalone/standalone/test/index.test.ts index fe8640be..01c6966d 100644 --- a/standalone/standalone/test/index.test.ts +++ b/standalone/standalone/test/index.test.ts @@ -84,7 +84,23 @@ describe('test/index.test.ts', () => { describe('runner with runtimeConfig', () => { it('should work', async () => { const msg = await main(path.join(__dirname, './fixtures/runtime-config')); - assert.deepEqual(msg, { baseDir: path.join(__dirname, './fixtures/runtime-config') }); + assert.deepEqual(msg, { + baseDir: path.join(__dirname, './fixtures/runtime-config'), + env: undefined, + name: undefined, + }); + }); + + it('should auto set name and env', async () => { + const msg = await main(path.join(__dirname, './fixtures/runtime-config'), { + name: 'foo', + env: 'unittest', + }); + assert.deepEqual(msg, { + baseDir: path.join(__dirname, './fixtures/runtime-config'), + name: 'foo', + env: 'unittest', + }); }); });