Skip to content

Commit

Permalink
Change configure tests
Browse files Browse the repository at this point in the history
Now using the prepare() method to test if configuration is resolved as desired.
  • Loading branch information
aedart committed Oct 6, 2024
1 parent 9760e09 commit 6ad896d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
40 changes: 37 additions & 3 deletions tests/browser/packages/core/application/configure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ import {
BaseConfigurator,
ConfigurationError
} from "@aedart/core";
import { Env } from "@aedart/support/env";

describe('@aedart/core', () => {
describe('configure', () => {

beforeEach(() => {
Env.clear();
});

afterEach(() => {
Env.clear();
});

it('fails when invalid configurator provided', () => {

class A {}
Expand Down Expand Up @@ -135,7 +144,7 @@ describe('@aedart/core', () => {
app.destroy();
});

it('configuration items are set', () => {
it('sets configuration items (after boot)', async () => {

const items = {
app: {
Expand All @@ -147,8 +156,8 @@ describe('@aedart/core', () => {

// ---------------------------------------------------------------------------- //

app
.configure( (configurator) => configurator.with(items) )
await app
.prepare(items)
.run();

// ---------------------------------------------------------------------------- //
Expand All @@ -163,5 +172,30 @@ describe('@aedart/core', () => {

app.destroy();
});

it('resolves external (async) configuration source and applies environment variables', async () => {

const app = new Application();

// ---------------------------------------------------------------------------- //

await app
.prepare(
async () => (await import('./fixtures/example-config')).default
)
.run();

// ---------------------------------------------------------------------------- //

const result = Config
.obtain()
.get('app.environment');

expect(result)
.withContext('External configuration was not resolved correctly')
.toBe('testing');

app.destroy();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { env } from "@aedart/support/env";

export default {
app: {
environment: env('APP_ENV')
}
}

0 comments on commit 6ad896d

Please sign in to comment.