Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: separate tests #424

Merged
merged 2 commits into from
Feb 2, 2024
Merged

test: separate tests #424

merged 2 commits into from
Feb 2, 2024

Conversation

nnecec
Copy link
Contributor

@nnecec nnecec commented Jan 23, 2024

resolve #389

@nnecec
Copy link
Contributor Author

nnecec commented Jan 23, 2024

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

@huozhi
Copy link
Owner

huozhi commented Jan 23, 2024

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
Copy link
Contributor Author

nnecec commented Jan 24, 2024

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
Copy link
Owner

huozhi commented Jan 24, 2024

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
}

test/utils/helper.ts Outdated Show resolved Hide resolved

expect(code).toBe(0)

await removeDirectory(distDir)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could remove removeDirectory(distDir), because we create dist in fixtures instead of createTempDir

@nnecec nnecec marked this pull request as ready for review January 26, 2024 15:02
@huozhi
Copy link
Owner

huozhi commented Jan 26, 2024

There're code conflicts

Copy link
Owner

@huozhi huozhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nnecec The purpose to have cli and integration tests's cli separate is:

Integration tests shouldn't need to specify a folder, it should be current __dirname by default always, no args. If we have one test file for each folder, case, instead group some of them in fixtures.

- integration/<xxx>
  |- src/...
  |- package.json
  |- index.test.js

Cli tests can have flexible args, but if the input.js filename is a fixed convention we don't need to do it.

I didn't expect we gonna change integration as well, as the early draft is only about cli. This is kinda a pretty big change now. If would be great if we can land the cli tests changes first, since they're not too much.

Then we get a new PR to change one integration test as an example, if it looks good we can migrate rest of them. It doesn't have to be a one time all migrated change.

Thank you!

expect(fs.existsSync(typeFile)).toBe(true)
expect(code).toBe(0)

await removeDirectory(distDir)
Copy link
Owner

@huozhi huozhi Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done in afterEach/afterAll

@huozhi
Copy link
Owner

huozhi commented Feb 2, 2024

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

@huozhi huozhi merged commit b4a9af1 into huozhi:main Feb 2, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create test suite, separate tests into each folder
2 participants