amiceli / vitest-cucumber

Use gherkin in your unit tests with vitest
https://vitest-cucumber.miceli.click
25 stars 2 forks source link

Suggestion: change the base path of loadFeature from cwd to the caller file's paths #49

Closed ytw0728 closed 3 months ago

ytw0728 commented 3 months ago

outline

as-is

// ./src/path/to/feature/foo.test.tsx

import { loadFeature } from '@amiceli/vitest-cucumber'

const feature = await loadFeature('./src/path/to/feature/foo.feature')
// ...

to-do

// ./src/path/to/feature/foo.test.tsx

import { loadFeature } from '@amiceli/vitest-cucumber'

const feature = await loadFeature('./foo.feature')
// ...

explanation

Hello there! I think the base path of loadFeature on as-is could cause a little trouble when we move a spec (or test) file to another path. (whenever that happens, it seems that we need to change each path that is passed to loadFeature as a parameter.)

so, I suggest changing the base path of it to the caller file's paths. or what do you think about making a loader for the feature file and connecting its result with your package?

I appreciate your efforts for this package.

related link

https://github.com/amiceli/vitest-cucumber/blob/10f97b60481e02a3e8554399218eac55f04f9a0a/src/vitest/load-feature.ts#L9-L10

amiceli commented 3 months ago

Hi @ytw0728 ,

Your issue is a good point ;). I make some search about it and I found posts and/or framework docs using both solutions : same folder or different folders.

So I will work on it to allow both ways. I will show you it on this issue and you will give me your opinion ;)

amiceli commented 3 months ago

@ytw0728 , I found a solution to load feature file in both ways. If you want, you can check code in #50 .

I'm working on it to improve my unit tests for it.

amiceli commented 3 months ago

It's done, I have published a new version https://github.com/amiceli/vitest-cucumber/releases/tag/v3.2.3 You can install new version to use relative path ;).

ytw0728 commented 3 months ago

@amiceli Thanks for your super fast solving!!! It looks much better than what I requested.

Have a wonderful one!