-
-
Notifications
You must be signed in to change notification settings - Fork 224
Add test suite for all current config loading systems #301
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together, Nicolas!
A few comments, but I'm sure we can merge this swiftly.
test/config/yaml.test.ts
Outdated
return error['stdout'].toString(); | ||
} | ||
// Unknown error | ||
throw error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper is great! Looks like it resolves #253 :)
Will be very useful going forward and testing CLI arguments, etc.
This looks like using the same exec
function in the new test files, do you think it could be a single reusable test helper? There's a test/helpers
folder for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing! Will do that ASAP 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ! I've used a "dumb" way where you need to pass the cli path, this could be enhanced further where the execFactory crawls back up to find the cli itself, but for a first iteration, I opted to keeping it KISS. Let me know what you think !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolving the path to cli.js
from the helper seems more ergonomic and clean, so would be great if you could still add that. Happy to merge either way!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the other comment, I've added it in the least intrusive way, since doing it the proper way could have an impact on test speed (fs apis to check for file and read files, for every test that uses the exec util)
Co-authored-by: Lars Kappert <lars@webpro.nl>
test/cli-preprocessor.test.ts
Outdated
console.error(`Error during execution of command: ${command}`); | ||
} | ||
}; | ||
const exec = execFactory(cwd, '../../dist/cli.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be an idea to resolve ../dist/cli.js
in the helper module using import.meta.url
from there? That would mean an argument less here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be done yes, but then if the files are in a different location (like the npm run test
script), then there need to be extra logic
const thisFileUrl = fileURLToPath(import.meta.url);
const cliPath = resolve(
thisFileUrl,
// Needed if run in the /tmp (like in the npm test script) to find the correct dist folder
thisFileUrl.endsWith('tmp/test/helpers/execKnip.js') ? '..' : '.',
'../../../dist/cli.js'
);
The safest way is to go back up to find the package.json with the name knip
, this way we are sure we are finding the right directory and is less prone to error if the test are moved around for example.
I've added the simple way, and I'll let you decide if it's worth the effort to look for the package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that /tmp
dir I forgot about.
Maybe something like require.resolve('dist/cli.js)
to make an absolute path that should be OK from anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be indeed ! Thank you for pushing the change directly to the branch :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, I was waiting for CI to pass 💚
Wanted to get it done 🏓 Let's merge it?
Many many thanks for the great improvements!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge it !
My pleasure ! I will experiment further with knip and the new dynamic capabilities ! I'll post my experiment on discord ;)
🚀 This pull request is included in v2.34.0. See Release 2.34.0 for release notes. |
This PR introduce two things :
A test suite to validate all config provider system, in a e2e manner :
knip
with aknip.js
file that expose an objectknip
with aknip.js
file that expose an async functionknip
with aknip.json
fileknip -c knip.mjs
with aknip.mjs
file that expose an objectknip -c knip.mjs
with aknip.mjs
file that expose an async functionknip
with a config into apackage.json#knip
knip
with aknip.ts
file that expose an async functionknip
with aknip.ts
file that expose a functionknip
with aknip.ts
file that expose an objectknip -c knip.yaml
with aknip.yaml
fileAnd enhance the current config loading mechanism to support js function & async function as a config export. I've added :
If you need anything modified, feel free to reach out ! And thanks for your work on Knip ❤️