Skip to content

Commit

Permalink
feat: add esbuild command for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Feb 16, 2024
1 parent b8a9f77 commit c1b18ac
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
36 changes: 36 additions & 0 deletions src/commands/esbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {Args, Command, Flags, Interfaces} from '@oclif/core'

type Result = {
args: Interfaces.InferredArgs<typeof ESBuild.args>
flags: Interfaces.InferredFlags<typeof ESBuild.flags>
}

export default class ESBuild extends Command {
static args = {
defaultArg: Args.string({
default: 'simple string default',
}),
defaultFnArg: Args.string({
default: async () => 'async fn default',
}),
optionalArg: Args.string(),
}

static enableJsonFlag = true

static flags = {
defaultFnString: Flags.string({
default: async () => 'async fn default',
}),
defaultString: Flags.string({
default: 'simple string default',
}),
optionalString: Flags.string(),
}

async run(): Promise<Result> {
const {args, flags} = await this.parse(ESBuild)
this.log(`hello I am a bundled (esbuild) plugin from ${this.config.root}!`)
return {args, flags}
}
}
6 changes: 3 additions & 3 deletions src/hooks/init/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Hook} from '@oclif/core'
import {Hook, ux} from '@oclif/core'

const hook: Hook<'init'> = async function (opts) {
process.stdout.write(`example hook running ${opts.id}\n`)
const hook: Hook<'init'> = async function () {
ux.log('Greetings! from plugin-test-esbuild init hook')
}

export default hook
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import ESBuild from './commands/esbuild'
import Hello from './commands/hello'
import HelloWorld from './commands/hello/world'
export {default as INIT_HOOK} from './hooks/init/init'

export const COMMANDS = {
esbuild: ESBuild,
hello: Hello,
'hello:alias': HelloWorld,
'hello:world': HelloWorld,
Expand Down
10 changes: 10 additions & 0 deletions test/commands/esbuild.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {expect, test} from '@oclif/test'

describe('esbuild', () => {
test
.stdout()
.command(['esbuild'])
.it('runs esbuild cmd', (ctx) => {
expect(ctx.stdout).to.contain('hello I am a bundled (esbuild) plugin')
})
})
19 changes: 14 additions & 5 deletions test/commands/hello/world.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ import {expect, test} from '@oclif/test'

describe('hello world', () => {
test
.stdout()
.command(['hello:world'])
.it('runs hello world cmd', ctx => {
expect(ctx.stdout).to.contain('hello world!')
})
.stdout()
.command(['hello:world'])
.it('runs hello world cmd', (ctx) => {
expect(ctx.stdout).to.contain('hello world!')
})
})

describe('hello alias', () => {
test
.stdout()
.command(['hello:alias'])
.it('runs hello alias cmd', (ctx) => {
expect(ctx.stdout).to.contain('hello world!')
})
})
8 changes: 4 additions & 4 deletions test/hooks/init/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {expect, test} from '@oclif/test'

describe('hooks', () => {
test
.stdout()
.hook('init', {id: 'mycommand'})
.do(output => expect(output.stdout).to.contain('example hook running mycommand'))
.it('shows a message')
.stdout()
.hook('init', {id: 'mycommand'})
.do((output) => expect(output.stdout).to.contain('Greetings! from plugin-test-esbuild init hook'))
.it('shows a message')
})

0 comments on commit c1b18ac

Please sign in to comment.