-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add ability to unload files from require cache (redux)
#3726
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
Changes from all commits
10fa3a1
5ca5761
6160e90
b03cf1f
96694e4
43ec922
cbef1e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| 'use strict'; | ||
|
|
||
| const path = require('path'); | ||
| const Mocha = require('../../lib/mocha'); | ||
| const utils = require('../../lib/utils'); | ||
|
|
||
| describe('Mocha', function() { | ||
| const opts = {reporter: utils.noop}; // no output | ||
| const testFiles = [ | ||
| __filename, | ||
| path.join(__dirname, 'cli', 'config.spec.js'), | ||
| path.join(__dirname, 'cli', 'run.spec.js') | ||
| ]; | ||
| const resolvedTestFiles = testFiles.map(require.resolve); | ||
|
|
||
| describe('#addFile', function() { | ||
| it('should add the given file to the files array', function() { | ||
| const mocha = new Mocha(opts); | ||
| mocha.addFile(__filename); | ||
| expect(mocha.files, 'to have length', 1).and('to contain', __filename); | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it('should be chainable', function() { | ||
| const mocha = new Mocha(opts); | ||
| expect(mocha.addFile(__filename), 'to be', mocha); | ||
| }); | ||
| }); | ||
|
|
||
| describe('#loadFiles', function() { | ||
| it('should load all files from the files array', function() { | ||
| const mocha = new Mocha(opts); | ||
|
|
||
| testFiles.forEach(mocha.addFile, mocha); | ||
| mocha.loadFiles(); | ||
| expect(require.cache, 'to have keys', resolvedTestFiles); | ||
| }); | ||
|
|
||
| it('should execute the optional callback if given', function() { | ||
| const mocha = new Mocha(opts); | ||
| expect(cb => { | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mocha.loadFiles(cb); | ||
| }, 'to call the callback'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.unloadFile', function() { | ||
| it('should unload a specific file from cache', function() { | ||
| const resolvedFilePath = require.resolve(__filename); | ||
| require(__filename); | ||
| expect(require.cache, 'to have key', resolvedFilePath); | ||
|
|
||
| Mocha.unloadFile(__filename); | ||
| expect(require.cache, 'not to have key', resolvedFilePath); | ||
| }); | ||
| }); | ||
|
|
||
| describe('#unloadFiles', function() { | ||
| it('should unload all test files from cache', function() { | ||
| const mocha = new Mocha(opts); | ||
|
|
||
| testFiles.forEach(mocha.addFile, mocha); | ||
| mocha.loadFiles(); | ||
| mocha.unloadFiles(); | ||
| expect(require.cache, 'not to have keys', resolvedTestFiles); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you just do
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was your idea to test against multiple files, a good one. This is somewhat how I would expect it to be used in the wild, so think this test should reflect expected usage black-box style, since the other was done as a white-box test. |
||
| }); | ||
|
|
||
| it('should be chainable', function() { | ||
| const mocha = new Mocha(opts); | ||
| expect(mocha.unloadFiles(), 'to be', mocha); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ describe('Mocha', function() { | |
| sandbox.stub(Mocha.prototype, 'useColors').returnsThis(); | ||
| sandbox.stub(utils, 'deprecate'); | ||
| }); | ||
|
|
||
| it('should prefer "color" over "useColors"', function() { | ||
| // eslint-disable-next-line no-new | ||
| new Mocha({useColors: true, color: false}); | ||
|
|
@@ -70,14 +71,6 @@ describe('Mocha', function() { | |
| }); | ||
| }); | ||
|
|
||
| describe('.addFile()', function() { | ||
| it('should add the given file to the files array', function() { | ||
| var mocha = new Mocha(opts); | ||
| mocha.addFile('myFile.js'); | ||
| expect(mocha.files, 'to have length', 1).and('to contain', 'myFile.js'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.invert()', function() { | ||
| it('should set the invert option to true', function() { | ||
| var mocha = new Mocha(opts); | ||
|
|
@@ -153,6 +146,7 @@ describe('Mocha', function() { | |
| expect(mocha.options, 'to have property', 'growl', true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('if not capable of notifications', function() { | ||
| it('should set the growl option to false', function() { | ||
| var mocha = new Mocha(opts); | ||
|
|
@@ -163,6 +157,7 @@ describe('Mocha', function() { | |
| expect(mocha.options, 'to have property', 'growl', false); | ||
| }); | ||
| }); | ||
|
|
||
| it('should be chainable', function() { | ||
| var mocha = new Mocha(opts); | ||
| expect(mocha.growl(), 'to be', mocha); | ||
|
|
@@ -195,11 +190,17 @@ describe('Mocha', function() { | |
| }); | ||
|
|
||
| describe('.noHighlighting()', function() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, should this test be here -- or in "browser-unit"? |
||
| // :NOTE: Browser-only option... | ||
| it('should set the noHighlighting option to true', function() { | ||
| var mocha = new Mocha(opts); | ||
| mocha.noHighlighting(); | ||
| expect(mocha.options, 'to have property', 'noHighlighting', true); | ||
| }); | ||
|
|
||
| it('should be chainable', function() { | ||
| var mocha = new Mocha(opts); | ||
| expect(mocha.noHighlighting(), 'to be', mocha); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.allowUncaught()', function() { | ||
|
|
@@ -208,6 +209,11 @@ describe('Mocha', function() { | |
| mocha.allowUncaught(); | ||
| expect(mocha.options, 'to have property', 'allowUncaught', true); | ||
| }); | ||
|
|
||
| it('should be chainable', function() { | ||
| var mocha = new Mocha(opts); | ||
| expect(mocha.allowUncaught(), 'to be', mocha); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.delay()', function() { | ||
|
|
@@ -216,6 +222,11 @@ describe('Mocha', function() { | |
| mocha.delay(); | ||
| expect(mocha.options, 'to have property', 'delay', true); | ||
| }); | ||
|
|
||
| it('should be chainable', function() { | ||
| var mocha = new Mocha(opts); | ||
| expect(mocha.delay(), 'to be', mocha); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.bail()', function() { | ||
|
|
@@ -224,6 +235,11 @@ describe('Mocha', function() { | |
| mocha.bail(); | ||
| expect(mocha.suite._bail, 'to be', true); | ||
| }); | ||
|
|
||
| it('should be chainable', function() { | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var mocha = new Mocha(opts); | ||
| expect(mocha.bail(), 'to be', mocha); | ||
| }); | ||
| }); | ||
|
|
||
| describe('error handling', function() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.