Skip to content

Commit

Permalink
fix: types and config inheritance for vite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dnotes committed Oct 9, 2024
1 parent b8a6860 commit e23b37b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-knives-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"quickpickle": patch
---

Fixed types and config passing for vite plugin
23 changes: 11 additions & 12 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addStepDefinition, findStepDefinitionMatch } from './steps';
import { get, defaults } from 'lodash-es';
import { tagsFunction } from './tags';
import { Plugin, ResolvedConfig as ViteResolvedConfig } from 'vite'
import {
BeforeAll, applyBeforeAllHooks,
Before, applyBeforeHooks,
Expand Down Expand Up @@ -53,7 +53,7 @@ interface StepDefinitionMatch {
}

export const qp = async (step: string, state: any, line: number, data?: any): Promise<any> => {
const stepDefinitionMatch = findStepDefinitionMatch(step);
const stepDefinitionMatch: StepDefinitionMatch = findStepDefinitionMatch(step);

// Set the state info
state.info.step = step
Expand All @@ -78,13 +78,13 @@ export const qp = async (step: string, state: any, line: number, data?: any): Pr
}
};

export type QuickPickleConfig = {
export type QuickPickleConfig<T = {[key:string]:any}> = {
todoTags: string|string[]
skipTags: string|string[]
failTags: string|string[]
concurrentTags: string|string[]
sequentialTags: string|string[]
worldConfig: {[key:string]:any}
worldConfig: T
};

export const defaultConfig: QuickPickleConfig = {
Expand Down Expand Up @@ -123,10 +123,8 @@ export const defaultConfig: QuickPickleConfig = {

}

interface ResolvedConfig {
test?: {
quickpickle?: Partial<QuickPickleConfig>;
};
interface ResolvedConfig extends ViteResolvedConfig {
quickpickle?: Partial<QuickPickleConfig>;
}

export function normalizeTags(tags?:string|string[]|undefined):string[] {
Expand All @@ -135,23 +133,24 @@ export function normalizeTags(tags?:string|string[]|undefined):string[] {
return tags.filter(Boolean).map(tag => tag.startsWith('@') ? tag : `@${tag}`)
}

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

return {
name: 'quickpickle-transform',
configResolved: (resolvedConfig: ResolvedConfig) => {
configResolved(resolvedConfig: ResolvedConfig) {
config = defaults(
defaultConfig,
get(resolvedConfig, 'test.quickpickle')
passedConfig,
get(resolvedConfig, 'quickpickle'),
) as QuickPickleConfig;
config.todoTags = normalizeTags(config.todoTags)
config.skipTags = normalizeTags(config.skipTags)
config.failTags = normalizeTags(config.failTags)
config.concurrentTags = normalizeTags(config.concurrentTags)
config.sequentialTags = normalizeTags(config.sequentialTags)
},
transform: async (src: string, id: string): Promise<string | undefined> => {
async transform(src: string, id: string) {
if (featureRegex.test(id)) {
return renderGherkin(src, config, id.match(/\.md$/) ? true : false)
}
Expand Down

0 comments on commit e23b37b

Please sign in to comment.