-
Notifications
You must be signed in to change notification settings - Fork 4
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
Reusable (and exportable) Test Cases - grouping check and integration stage tests #435
Comments
For now if we do want create "allow list" tests, we can continue to use directories, but we just need to copy/duplicate the test cases. It would require that the regular Alternatively we move |
@emmacasolin I remember you were looking into a custom runner when we were originally doing the sharding. Now I find https://stackoverflow.com/questions/47722048/getting-a-list-of-tests-run-with-jest-without-running-suites. It seems jest does have a way of just getting all the tests as structural information without running them. Is it possible that we may preserve the existing jest code and somehow extract structure to reuse it? |
This was for the |
Hmm in that case, the only solution maybe to create alternative |
I think I found a library that can help do this: https://github.com/testdeck/testdeck. They support writing tests in an OOP style. Appears to support jest. I'm not sure if any other limitations. It seems their way of re-using tests is to write abstract tests, and then import them into concrete tests by way of class extension. Is this any different from just writing test functions, then importing them to run within Test nesting is also suggested as one can dynamically create tests. In a way, I'm suggesting that all tests should be written in an abstract way so they can be imported to another test file. |
With #437 and #436, there will be pending fixes here:
|
The only practical solution right now is something like: import parameterisedTest from '..somecommontestmodule..';
describe('', () => {
test('', parameterisedTest(p1, p2));
}); The idea is that Doing this though, we need to be careful about any side-effects coming from This way we separate the "test structure" from the actual test itself which can be shared among different test files. describe('', () => {
const obj = {};
beforeEach(() => {
obj.x = 3;
});
test('', parameterisedTest(obj));
}); |
Specification
As we are moving towards greater amounts of integration testing, there are lot of existing unit tests that we would like to run, but only during integration. Particularly right now, we are using
tests/bin
as both the unit tests for the CLI, but also integration testing in the docker platform, and eventually for windows MatrixAI/Polykey-CLI#11 and macos MatrixAI/Polykey-CLI#12.Once we standardise conditional testing #434, we will have the ability to use
npm test
to automatically run all tests, while conditional utilities would use "feature flags" to determine whether the test should run or not.However this doesn't allow us to specify a select group of tests to run. The conditional testing only allows us to say what tests should not be running. This means conditional testing utilities is primarily useful for unit testing stage, where we test everything, but disable certain unit tests when certain conditions are not true.
Instead for integration tests, we need a better "grouping specification" to say instead that these group of tests we do want to test. Think of this as the "allow list" in comparison to the "disallow list" that conditional testing utilities represent. The "disallow list" here would be applied after the "allow list" is applied first.
Originally we evaluated the usage of
jest-runner-groups
, but I didn't like it's comment annotation implementation and the lack of defined behaviour on edge cases.Instead I believe directories are good way of structuring tests as we have historically done, and we should be able to reuse directories for "allow list" grouping that would be useful for the integration testing stage.
This would mean rather than running
npm test -- tests/bin
under docker integration testing, oen could do insteadnpm test -- tests/integration/docker
, only allowing tests under thetests/integration/docker
during the docker platform. At the same time, this means general unit testing would need to ignore the integration directory.To avoid copying/duplicating all the tests however, we would need to be able to re-use test cases defined in other directories, and this means the ability to export test cases to be lazily executed.
Here's an initial prototype:
The only issue with this, is that it's very coarse-grained, it just allows one to reimport tests from another file, but one cannot dig into the nested test structure, it's just all side effects. If we wanted to be able to selectively execute individual tests from a different test file, we would need something like:
I believe rather than writing the full object structure out, we would want to augment the
describe
andtest
functions to be non-imperative, that is the same functions are used, but instead of executing side effects, they end up producing a structure like above that can then be lazily evaluated.Where
g
could benew JestLazy
or something.That way we can re-use
testIf
andtest.only
... etc.Finally after all of this, we can then write tests under
tests/integration/docker
, and create our own tests specifically for docker, or import tests like:I think this requires quite some amount of iteration to get it right before we apply it all of the tests.
Additional context
Maybe our
testIf
should actually betest.if
if we "integrate" into jest's structure. For exampletest.each
andtest.only
, so why nottest.if
. See: https://softwarewright.dev/blog/posts/jest-unit-testing/extending-jest.htmlTasks
The text was updated successfully, but these errors were encountered: