-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 improve(patch): add @types/node to create bud app
- Loading branch information
1 parent
63225e4
commit 8d16ed5
Showing
28 changed files
with
699 additions
and
102 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
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
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 |
---|---|---|
@@ -1,24 +1,46 @@ | ||
import {Bud, factory} from '@repo/test-kit' | ||
import {bootstrap as subject} from '@roots/bud-framework/bootstrap' | ||
import {beforeEach, describe, expect, it, vi} from 'vitest' | ||
import {path} from '@repo/constants' | ||
import {factory} from '@repo/test-kit' | ||
import {describe, expect, it} from 'vitest' | ||
|
||
describe( | ||
`bootstrap`, | ||
function () { | ||
let bud: Bud | ||
let bootstrap: typeof subject | ||
import {bootstrap} from '../src/bootstrap/index.js' | ||
import {Bud} from '../src/bud/index.js' | ||
|
||
beforeEach(async () => { | ||
vi.clearAllMocks() | ||
bud = await factory() | ||
bud.context.basedir = `/foo` | ||
bud.path = vi.fn(() => `/test-return`) | ||
bootstrap = subject.bind(bud) | ||
}) | ||
describe(`bootstrap`, {retry: 2}, function () { | ||
it(`is a function`, () => { | ||
expect(bootstrap).toBeInstanceOf(Function) | ||
}) | ||
|
||
it(`returns Bud`, async () => { | ||
const value = await bootstrap( | ||
await factory({ | ||
basedir: path(`tests/util/project`), | ||
dry: true, | ||
}), | ||
) | ||
expect(value.constructor.name).toEqual(`Bud`) | ||
}) | ||
|
||
it(`is a function`, () => { | ||
expect(bootstrap).toBeInstanceOf(Function) | ||
it(`should call methods`, async () => { | ||
const value = await bootstrap( | ||
await factory({ | ||
basedir: path(`tests/util/project`), | ||
dry: true, | ||
}), | ||
) | ||
expect(value.context.dry).toBe(true) | ||
expect(value.context.basedir).toBe(path(`tests/util/project`)) | ||
}) | ||
|
||
it(`child instances should reference bud.root.module`, async () => { | ||
const root = await factory({ | ||
basedir: path(`tests/util/project`), | ||
dry: true, | ||
}) | ||
}, | ||
{retry: 2}, | ||
) | ||
await root.make(`foo`) | ||
const child = root.get(`foo`) | ||
|
||
const value = await bootstrap(child) | ||
expect(value.isRoot).toBe(false) | ||
expect(value.module).toBe(root.module) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,21 +1,30 @@ | ||
import {Bud} from '@roots/bud-framework/bud' | ||
import type {Context} from '@roots/bud-framework' | ||
|
||
import {describe, expect, it} from 'vitest' | ||
|
||
import {Bud} from '../src/bud/index.js' | ||
|
||
describe(`Bud`, function () { | ||
it(`is a class`, () => { | ||
expect(Bud).toBeInstanceOf(Function) | ||
}) | ||
|
||
it(`is a constructor`, () => { | ||
expect(new Bud()).toBeInstanceOf(Bud) | ||
expect(new Bud({} as Context)).toBeInstanceOf(Bud) | ||
}) | ||
|
||
it(`throws when bootstrapped with no context`, async () => { | ||
it(`throws when constructed with no context`, async () => { | ||
try { | ||
// @ts-ignore | ||
expect(await new Bud().lifecycle()).toThrowError() | ||
expect(new Bud()).toThrowError() | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(Error) | ||
} | ||
}) | ||
|
||
it(`has an executeServiceCallbacks method`, async () => { | ||
expect(new Bud({} as Context).executeServiceCallbacks).toBeInstanceOf( | ||
Function, | ||
) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,18 +1,92 @@ | ||
import {factory} from '@repo/test-kit' | ||
import {Bud} from '@roots/bud' | ||
import Env from '@roots/bud-framework/env' | ||
import {type Bud} from '@repo/test-kit' | ||
import {beforeEach, describe, expect, it} from 'vitest' | ||
|
||
describe(`@roots/bud/services/env`, () => { | ||
let bud: Bud | ||
import Env from '../src/env/index.js' | ||
|
||
beforeEach(async () => { | ||
bud = (await factory()) as Bud | ||
}) | ||
|
||
it(`is a container service`, async () => { | ||
const bud = await factory() | ||
describe(`@roots/bud-framework/env`, () => { | ||
it(`should be a container service`, async () => { | ||
const bud = { | ||
context: { | ||
env: {}, | ||
}, | ||
} as Bud | ||
const instance = new Env(() => bud) | ||
expect(instance.constructor.name).toBe(`Env`) | ||
}) | ||
|
||
describe(`getPublicEnv`, () => { | ||
it(`should return the public env variables`, async () => { | ||
const bud = { | ||
context: { | ||
env: { | ||
PRIVATE_TEST: `test`, | ||
PUBLIC_TEST: `test`, | ||
}, | ||
}, | ||
} as unknown as Bud | ||
const instance = new Env(() => bud) | ||
await instance.bootstrap(bud) | ||
expect(instance.getPublicEnv()).toStrictEqual({ | ||
TEST: `test`, | ||
}) | ||
}) | ||
}) | ||
|
||
describe(`getEnv`, () => { | ||
it(`should return the env variables`, async () => { | ||
const bud = { | ||
context: { | ||
env: { | ||
PRIVATE_TEST: `test`, | ||
PUBLIC_TEST: `test`, | ||
}, | ||
}, | ||
} as unknown as Bud | ||
const instance = new Env(() => bud) | ||
await instance.bootstrap(bud) | ||
expect(instance.all()).toStrictEqual({ | ||
PRIVATE_TEST: `test`, | ||
PUBLIC_TEST: `test`, | ||
}) | ||
}) | ||
}) | ||
|
||
describe(`initial values`, async () => { | ||
it(`should coerce 'true' to true`, async () => { | ||
const bud = { | ||
context: { | ||
env: { | ||
TEST: `true`, | ||
}, | ||
}, | ||
} as unknown as Bud | ||
const instance = new Env(() => bud) | ||
await instance.bootstrap(bud) | ||
expect(instance.get(`TEST`)).toBe(true) | ||
}) | ||
|
||
it(`should coerce 'false' to false`, async () => { | ||
const bud = { | ||
context: { | ||
env: { | ||
TEST: `false`, | ||
}, | ||
}, | ||
} as unknown as Bud | ||
const instance = new Env(() => bud) | ||
await instance.bootstrap(bud) | ||
expect(instance.get(`TEST`)).toBe(false) | ||
}) | ||
|
||
it(`should be fine with no initial env`, async () => { | ||
const bud = { | ||
context: { | ||
env: {}, | ||
}, | ||
} as unknown as Bud | ||
const instance = new Env(() => bud) | ||
await instance.bootstrap(bud) | ||
expect(instance.repository).toStrictEqual({}) | ||
}) | ||
}) | ||
}) |
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
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
39 changes: 39 additions & 0 deletions
39
sources/@roots/bud-framework/test/extension/decorators/options.test.ts
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,39 @@ | ||
import {beforeAll, describe, expect, it, vi} from 'vitest' | ||
|
||
import {options} from '../../../src/extension/decorators/options.js' | ||
import {type Bud, Extension} from '../../../src/index.js' | ||
|
||
// @ts-ignore | ||
@options({ | ||
foo: `bar`, | ||
}) | ||
class TestExtension extends Extension {} | ||
|
||
describe(`@roots/bud-framework/extension/decorators/options`, () => { | ||
let bud: Bud | ||
|
||
beforeAll(async () => { | ||
bud = { | ||
module: { | ||
import: vi.fn(async (...args: any[]) => {}), | ||
resolve: vi.fn(async (...args: any[]) => {}), | ||
}, | ||
resolvePromises: vi.fn(async (...args: any[]) => {}), | ||
} as unknown as Bud | ||
}) | ||
|
||
it(`should return a decorator`, () => { | ||
// @ts-ignore | ||
expect(options({foo: `bar`})).toBeInstanceOf(Function) | ||
}) | ||
|
||
it(`should add a _options property to the class`, () => { | ||
// @ts-ignore | ||
expect(new TestExtension(bud)._options).toEqual({foo: `bar`}) | ||
}) | ||
|
||
it(`should add a options property to the class`, () => { | ||
// @ts-ignore | ||
expect(new TestExtension(bud).options).toEqual({foo: `bar`}) | ||
}) | ||
}) |
Oops, something went wrong.