Skip to content

test: consuming this library in various scenarios #164

Open
patricktree wants to merge 18 commits into
alexreardon:masterfrom
patricktree:test/lib-consumption
Open

test: consuming this library in various scenarios #164
patricktree wants to merge 18 commits into
alexreardon:masterfrom
patricktree:test/lib-consumption

Conversation

@patricktree
Copy link
Copy Markdown
Contributor

@patricktree patricktree commented Nov 19, 2022

Problem

tiny-invariant should compile and run in various setups. Be it Node-CJS, Node-ESM, TypeScript projects with various configurations, in Browsers, etc.
On this matter we had some troubles in the past (#144, #151) and we have a new issue (#162).
Iterating on this topic - package consumption in different scenarios - is difficult and error-prone at the moment.

Proposed Solution

Add tests which validate that tiny-invariant compiles and runs in different scenarios.

This PR implements a package.json script test:pkg-consumption which uses @pkerschbaum/pkg-consumption-test to run "package consumption scenarios".
Those scenarios are implemented in /test-pkg-consumption.

Four scenarios are implemented with this PR. Locally I added a fifth scenario for #162, and it successfully reproduces the issue.
In other words, when working on a fix for #162 one can just work against that failing scenario, while making sure that the others don't break.

Notes

  • A GitHub action is also added running the test, similar to the unit tests.

Comment thread jest.config.js Outdated
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
testEnvironment: 'node',
rootDir: './test',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Jest would execute the .spec files in the directory test-lib-consumption without that.

Comment thread test-lib-consumption/main.spec.mts Outdated
it(`scenario "${scenarioDirectory.name}"`, async () => {
const pathToDirectory = path.join(PATHS.SCENARIOS_DIRECTORY, scenarioDirectory.name);
$.cwd = pathToDirectory;
await $`npm install --package-lock=false`;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

npm install is used here (instead of yarn) because for the scenarios it does not matter - they just fetch dependencies from Verdaccio and that's it.

@alexreardon
Copy link
Copy Markdown
Owner

This looks like a fantastic change. I am so sorry for not getting back to you sooner! I have been walking through a bit of burnout. I hope to look at this thoroughly in the new year

@patricktree
Copy link
Copy Markdown
Contributor Author

No problem!
Yes lets get back to it next year 👍

@alexreardon
Copy link
Copy Markdown
Owner

@pkerschbaum I love the goal and outcome of this change. Something I am thinking about is that this is a lot of code and complexity to add to this (little) package. I wonder if there is some way to pull what you have done out into another place (eg a package) which then tiny-invariant can use (reducing the complexity of this repo). What do you think?

@patricktree
Copy link
Copy Markdown
Contributor Author

@alexreardon I was actually able to create a package @pkerschbaum/pkg-consumption-test which exposes a command to run the tests!
Now the changes in this repository tiny-invariant are only the "package consumption scenarios" (and the GitHub workflow) to run the tests :)

@patricktree
Copy link
Copy Markdown
Contributor Author

I also updated the description of the PR.

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.

2 participants