question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Separate module options from test environment

See original GitHub issue

Related:

Note that there are two ways to set before/after hooks (which are currently the only module options): as properties on an options object, and as methods on the argument passed to a callback. Exposing environment procedurally is easy (e.g., a writable environment property on the callback argument), but the declarative side makes backcompat tough. I’m not particularly thrilled with the thought of adding a fourth parameter, though… we could instead look for an environment property on the second argument, using it exclusively when present (technically backwards incompatible, but on the same scale as #919) and otherwise generating warnings whenever there’s any non-before non-after property. All of which, of course, is assuming that keeping the declarative/procedural duality is valuable, about which I’m not fully persuaded but am inclined to keep for now (in part since the procedural interface is so new).

For example, all of these would generate the same environment for their tests:

QUnit.module(name, {
    beforeEach: function() {…},
    environment: { preserved: true },  // new
    ignored: true
});

// Define tests
…
QUnit.module(name, function( hooks ) {
    hooks.environment = { preserved: true };  // new
    hooks.beforeEach(function() {…});

    // Define tests
    …
});
QUnit.module(name, {
    beforeEach: function() {…},
    // For compat with current QUnit (if no environment is defined).
    preserved: true
});

// Define tests
…

But the last would issue warnings about deprecated options/environment mixing.

I’m not in love with this, but it’s the best I’ve got. Other suggestions welcome.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
raycohencommented, Aug 25, 2020

Thanks @Krinkle that is reassuring. I have found that lexical scoping can run into issues with nested modules depending on where you reassign, while using the this test environment is less easily be impacted by what happens in sibling modules. I might open another issue to discuss this since it’s not really on topic with this thread.

0reactions
raycohencommented, Nov 7, 2020

Ok, I see how hooks.before is accomplishing the same thing. I didn’t have a good understanding of when before ran in nested modules.

One other concern I had with the lexical version is the possibility for “leaks” - i.e. that inserting/deleting/re-ordering nested modules that run before another nested module that does not itself set a lexical variable could impact it. Example: http://jsfiddle.net/v94pze5k/ - granted the developer will see this error at dev time (or via CI) but understanding why a leaky breakage like this happened in a large test file can be a lot of work.

As for the options object, we don’t use that form, so I have no concerns with deprecating that behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should Python unittests be in a separate module?
YES, do use a separate module. It does not really make sense to use the __main__ trick. Just assume that you have several...
Read more >
Environment Modules — Modules documentation
The Modules package is a tool that simplifies shell initialization and lets users easily modify their environment during a session using modulefiles. Each ......
Read more >
What is Integration Testing (Tutorial ... - Software Testing Help
The main function or goal of this testing is to test the interfaces between the units/modules. The individual modules are first tested in ......
Read more >
Advanced test setup - Android Developers
Advanced test setups. ... Change the test build type; Configure Gradle test options; Use separate test modules for instrumented tests.
Read more >
Deploy and test the modules - IBM
You must deploy (publish) your module to your test environment server before you can run and test your mediation. About this task. In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found