Skip to content

Commit

Permalink
fix: config inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
dnotes committed Oct 10, 2024
1 parent 41889bb commit b3f2ba4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-spies-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"quickpickle": patch
---

Fixed config inheritance
13 changes: 8 additions & 5 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,19 @@ export function normalizeTags(tags?:string|string[]|undefined):string[] {
return tags.filter(Boolean).map(tag => tag.startsWith('@') ? tag : `@${tag}`)
}

export const quickpickle = (passedConfig:Partial<QuickPickleConfig> = {}): Plugin => {
let config: QuickPickleConfig;
export const quickpickle = (conf:Partial<QuickPickleConfig> = {}):Plugin => {
let config:QuickPickleConfig
let passedConfig = {...conf}

return {
name: 'quickpickle-transform',
configResolved(resolvedConfig: ResolvedConfig) {
config = defaults(
config = Object.assign(
{},
defaultConfig,
passedConfig,
get(resolvedConfig, 'quickpickle'),
get(resolvedConfig, 'quickpickle') || {},
get(resolvedConfig, 'test.quickpickle') || {},
) as QuickPickleConfig;
config.todoTags = normalizeTags(config.todoTags)
config.skipTags = normalizeTags(config.skipTags)
Expand All @@ -154,7 +157,7 @@ export const quickpickle = (passedConfig:Partial<QuickPickleConfig> = {}): Plugi
if (featureRegex.test(id)) {
return renderGherkin(src, config, id.match(/\.md$/) ? true : false)
}
}
},
};
}

Expand Down
50 changes: 50 additions & 0 deletions packages/main/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, expect, test, ResolvedConfig } from 'vitest'
import { quickpickle } from '../src/index'


describe('quickpickle plugin function', async () => {
const passedConfig = {
skipTags: ['@overwritten-skip'],
todoTags: ['@real-todo'],
worldConfig: {
headless: false,
slowMo: 50,
}
}

const viteConfig = {
quickpickle: { skipTags: ['@real-skip'] }
}
const plugin = quickpickle(passedConfig)

const featureText = `
@overwritten-skip @skip
Feature: Test Feature
@real-todo
Scenario: Not skipped, but todo
@real-skip
Scenario: Skipped
Given I run the tests
`

// @ts-ignore because we just need to check that the config is resolved in our plugin
plugin.configResolved(viteConfig)
// @ts-ignore
const output = await plugin.transform(featureText, 'test.feature')
console.log(output)

test('transform function overwrites default config with passed config, then vite config', () => {
expect(output).toContain(`test.todo('Scenario: Not skipped, but todo`)
expect(output).toContain(`test.skip('Scenario: Skipped`)
expect(output).not.toContain(`describe.skip`)
})

test('transform function writes worldConfig to output', () => {
expect(output).toContain(`"slowMo":50`)
expect(output).toContain(`"headless":false`)
})

})

0 comments on commit b3f2ba4

Please sign in to comment.