huozhi / bunchee

Zero config bundler for ECMAScript and TypeScript packages
https://npmjs.com/bunchee
948 stars 29 forks source link

test: separate tests #424

Closed nnecec closed 10 months ago

nnecec commented 10 months ago

resolve https://github.com/huozhi/bunchee/issues/389

nnecec commented 10 months ago

Is this the change we want? I can do more work if this is expected.

huozhi commented 10 months ago

Thanks for the PR. The expectation is each test will have its own test file like ./test/cli/<test case>/index.test.ts so the code are organized in the <test case> folder, and we can use a test helper to create test to write less code in each file

nnecec commented 10 months ago

I separated cli tests into multiple folders. If the same fixture is used, I put the test cases together in a index.test.ts.

Request CR, thanks!

huozhi commented 10 months ago

I was thinking to get a helper that automatically create a test directory for each test, and then use the fixed input filename, in each folder.

So each test you only need to call the helper, and pass the directory (maybe just __dirname) and received the code, stderr, stdout etc. you just need to test them. Similar to what we had before

// we have a generic helper `createTest`, that can define what does the executor do
const createCliTest = createTest({
   run(input, args) {
     // do cli work
     executeBunchee(...)
   }
})

// in each test, `createCliTest` can return the result
it(...) {
   const { code, stdout, distFiles, ... } = createCliTest({ directory: __dirname, args: [...] })
   // test stdout etc
}
huozhi commented 10 months ago

There're code conflicts

huozhi commented 10 months ago

Thanks for the PR, let's tackle the improves in the separate PR, will merge this for now