Add assertion to run after loading source to look for globals #347

Closed
jzaefferer opened this Issue Nov 6, 2012 · 4 comments

Comments

2 participants
@jzaefferer
Member

jzaefferer commented Nov 6, 2012

Something like this:

<script src="punycode.js"></script>
<script>QUnit.newGlobals('punycode');</script>

If punycode.js exports more than just a punycode window property, the assertion would fail.

@rodneyrehm

This comment has been minimized.

Show comment Hide comment
@rodneyrehm

rodneyrehm Nov 6, 2012

Contributor

While QUnit already has a feature detecting (accidental) globals caused by running the tests, there is no solution for finding those unwanted globals created by the source files. It is important to output the filename that created the global. A real bonus would be a line-number where it happened.

Does it make sense to extend this "global leak detection" to pass any scope (e.g. jQuery.fn) for validation?

Contributor

rodneyrehm commented Nov 6, 2012

While QUnit already has a feature detecting (accidental) globals caused by running the tests, there is no solution for finding those unwanted globals created by the source files. It is important to output the filename that created the global. A real bonus would be a line-number where it happened.

Does it make sense to extend this "global leak detection" to pass any scope (e.g. jQuery.fn) for validation?

@rodneyrehm

This comment has been minimized.

Show comment Hide comment
@rodneyrehm

rodneyrehm Dec 18, 2012

Contributor

I'm not entirely sure why files should be loaded using <script> in HTML. A registration along the following lines would

a) potentially allow simpler inclusion javascript controlled test runners
b) allow automatic global leak detection

<script src=".../qunit.js"></script>
<script>
  QUnit.js([
     // simple loading without leak-test
    'src/some-file.js',
    // loading with leak-test
    { file: 'src/some-other-file.js', exposes: ['globalVariable'] }
  ]);
</script>

This might also test if the expected global variables were actually defined.

In a way, I guess I'm proposing to (additionally) allow configuration by javascript only. So you don't have to create some qunit container and stuff. just load qunit.js, tell it what you need, have it load the files and create the dom it needs.

Contributor

rodneyrehm commented Dec 18, 2012

I'm not entirely sure why files should be loaded using <script> in HTML. A registration along the following lines would

a) potentially allow simpler inclusion javascript controlled test runners
b) allow automatic global leak detection

<script src=".../qunit.js"></script>
<script>
  QUnit.js([
     // simple loading without leak-test
    'src/some-file.js',
    // loading with leak-test
    { file: 'src/some-other-file.js', exposes: ['globalVariable'] }
  ]);
</script>

This might also test if the expected global variables were actually defined.

In a way, I guess I'm proposing to (additionally) allow configuration by javascript only. So you don't have to create some qunit container and stuff. just load qunit.js, tell it what you need, have it load the files and create the dom it needs.

@jzaefferer

This comment has been minimized.

Show comment Hide comment
@jzaefferer

jzaefferer Dec 18, 2012

Member

There's something similar in jQuery UI, there called TestHelpers: https://github.com/jquery/jquery-ui/blob/master/tests/unit/autocomplete/autocomplete.html#L13 - though its used to load the code to be tested, not the actual tests.

Member

jzaefferer commented Dec 18, 2012

There's something similar in jQuery UI, there called TestHelpers: https://github.com/jquery/jquery-ui/blob/master/tests/unit/autocomplete/autocomplete.html#L13 - though its used to load the code to be tested, not the actual tests.

@jzaefferer

This comment has been minimized.

Show comment Hide comment
@jzaefferer

jzaefferer Feb 13, 2014

Member

Closing this, doesn't really seem useful enough.

Member

jzaefferer commented Feb 13, 2014

Closing this, doesn't really seem useful enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment