Skip to content
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
3 changes: 1 addition & 2 deletions core/common-util/src/ModuleConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ export class ModuleConfigUtil {
envConfig = ModuleConfigUtil.loadModuleJsonSync(moduleDir, env);
}
}
extend(true, defaultConfig, envConfig);
return defaultConfig;
return extend(true, defaultConfig, envConfig);
}

private static loadModuleJsonSync(moduleDir: string, env?: string): ModuleConfig | undefined {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ContextProto, Inject, SingletonProto, ModuleConfigs } from '@eggjs/tegg';
import { Runner, MainRunner } from '@eggjs/tegg/standalone';

@SingletonProto()
export class Hello {
hello() {
return 'hello!';
}
}

@ContextProto()
export class HelloContext {
hello() {
return 'hello from ctx';
}
}

@ContextProto()
@Runner()
export class Foo implements MainRunner<object> {
@Inject()
moduleConfigs: ModuleConfigs;

async main(): Promise<object> {
return this.moduleConfigs.get('simple')!;
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "simple",
"eggModule": {
"name": "simple"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ContextProto, Inject, SingletonProto, ModuleConfigs } from '@eggjs/tegg';
import { Runner, MainRunner } from '@eggjs/tegg/standalone';

@SingletonProto()
export class Hello {
hello() {
return 'hello!';
}
}

@ContextProto()
export class HelloContext {
hello() {
return 'hello from ctx';
}
}

@ContextProto()
@Runner()
export class Foo implements MainRunner<object> {
@Inject()
moduleConfigs: ModuleConfigs;

async main(): Promise<object> {
return this.moduleConfigs.get('simple')!;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
features:
dynamic:
foo: 'foo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "simple",
"eggModule": {
"name": "simple"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function LogPath(name: string) {
accessLevel: AccessLevel.PUBLIC,
getObjects(ctx: MultiInstancePrototypeGetObjectsContext) {
const config = ModuleConfigUtil.loadModuleConfigSync(ctx.unitPath);
const logger = (config as any)?.features.logger;
const logger = (config as any)?.features?.logger;
if (!logger) {
return [];
}
Expand Down
38 changes: 27 additions & 11 deletions standalone/standalone/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import { strict as assert } from 'node:assert';
import path from 'node:path';
import fs from 'node:fs/promises';
import { main, StandaloneContext, Runner } from '..';
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('test/index.test.ts', () => {
describe('module with config', () => {
it('should work', async () => {
const config = await main(path.join(__dirname, './fixtures/module-with-config'));
assert.deepStrictEqual(config, {
assert.deepEqual(config, {
features: {
dynamic: {
foo: 'bar',
Expand All @@ -70,7 +70,23 @@ describe('test/index.test.ts', () => {
const config = await main(path.join(__dirname, './fixtures/module-with-env-config'), {
env: 'dev',
});
assert.deepStrictEqual(config, {
assert.deepEqual(config, {
features: {
dynamic: {
foo: 'foo',
},
},
});
});

it('should empty config work', async () => {
const config = await main(path.join(__dirname, './fixtures/module-with-empty-config'));
assert.deepEqual(config, {});
});

it('should empty default config work', async () => {
const config = await main(path.join(__dirname, './fixtures/module-with-empty-default-config'), { env: 'dev' });
assert.deepEqual(config, {
features: {
dynamic: {
foo: 'foo',
Expand All @@ -87,8 +103,8 @@ describe('test/index.test.ts', () => {
foo: ModuleConfig,
bar: ModuleConfig,
};
assert.deepStrictEqual(configs.get('foo'), foo);
assert.deepStrictEqual(configs.get('bar'), bar);
assert.deepEqual(configs.get('foo'), foo);
assert.deepEqual(configs.get('bar'), bar);
});
});

Expand Down Expand Up @@ -143,7 +159,7 @@ describe('test/index.test.ts', () => {

it('should work', async () => {
const msgs = await main(fixturePath);
assert.deepStrictEqual(msgs, [
assert.deepEqual(msgs, [
'hello, foo(context:0)',
'hello, bar(context:0)',
'hello, foo(singleton:0)',
Expand All @@ -157,7 +173,7 @@ describe('test/index.test.ts', () => {

it('should work', async () => {
const msg = await main(fixturePath);
assert.deepStrictEqual(msg,
assert.deepEqual(msg,
`withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))${JSON.stringify(pointcutAdviceParams)})${JSON.stringify(crosscutAdviceParams)})`);
});
});
Expand All @@ -174,11 +190,11 @@ describe('test/index.test.ts', () => {
for (const loadunit of loadunits) {
for (const proto of loadunit.iterateEggPrototype()) {
if (proto.id.match(/:hello$/)) {
assert.strictEqual(proto.className, 'Hello');
assert.equal(proto.className, 'Hello');
} else if (proto.id.match(/:moduleConfigs$/)) {
assert.strictEqual(proto.className, undefined);
assert.equal(proto.className, undefined);
} else if (proto.id.match(/:moduleConfig$/)) {
assert.strictEqual(proto.className, undefined);
assert.equal(proto.className, undefined);
}
}
}
Expand All @@ -190,7 +206,7 @@ describe('test/index.test.ts', () => {
for (const loadunit of loadunits) {
for (const proto of loadunit.iterateEggPrototype()) {
if (proto.id.match(/:dynamicLogger$/)) {
assert.strictEqual(proto.className, 'DynamicLogger');
assert.equal(proto.className, 'DynamicLogger');
}
}
}
Expand Down