diff options
Diffstat (limited to 'tests/lib/mocha-3.1.0/test/acceptance')
35 files changed, 0 insertions, 1550 deletions
diff --git a/tests/lib/mocha-3.1.0/test/acceptance/context.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/context.spec.js deleted file mode 100644 index 69dea139c9..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/context.spec.js +++ /dev/null @@ -1,72 +0,0 @@ -describe('Context', function(){ - beforeEach(function(){ - this.calls = ['before']; - }) - - describe('nested', function(){ - beforeEach(function(){ - this.calls.push('before two'); - }) - - it('should work', function(){ - expect(this.calls).to.eql(['before', 'before two']); - this.calls.push('test'); - }) - - after(function(){ - expect(this.calls).to.eql(['before', 'before two', 'test']); - this.calls.push('after two'); - }) - }) - - after(function(){ - expect(this.calls).to.eql(['before', 'before two', 'test', 'after two']); - }) -}) - -describe('Context Siblings', function(){ - beforeEach(function(){ - this.calls = ['before']; - }) - - describe('sequestered sibling', function(){ - beforeEach(function(){ - this.calls.push('before two'); - this.hiddenFromSibling = 'This should be hidden'; - }) - - it('should work', function(){ - expect(this.hiddenFromSibling).to.eql('This should be hidden') - }) - }) - - describe('sibling verifiction', function(){ - beforeEach(function(){ - this.calls.push('before sibling'); - }) - - it('should not have value set within a sibling describe', function(){ - expect('This should be hidden').not.to.eql(this.hiddenFromSibling); - this.visibleFromTestSibling = 'Visible from test sibling'; - }) - - it('should allow test siblings to modify shared context', function(){ - expect('Visible from test sibling').to.eql(this.visibleFromTestSibling); - }) - - it('should have reset this.calls before describe', function(){ - expect(this.calls).to.eql(['before', 'before sibling']); - }) - }) - - after(function(){ - expect(this.calls).to.eql(['before', 'before sibling']); - }) - -}) - -describe('timeout()', function(){ - it('should return the timeout', function(){ - expect(this.timeout()).to.equal(200); - }); -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/duration.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/duration.spec.js deleted file mode 100644 index 4f319b8a3c..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/duration.spec.js +++ /dev/null @@ -1,25 +0,0 @@ -describe('durations', function(){ - describe('when slow', function(){ - it('should highlight in red', function(done){ - setTimeout(function(){ - done(); - }, 100); - }) - }) - - describe('when reasonable', function(){ - it('should highlight in yellow', function(done){ - setTimeout(function(){ - done(); - }, 50); - }) - }) - - describe('when fast', function(){ - it('should highlight in green', function(done){ - setTimeout(function(){ - done(); - }, 10); - }) - }) -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/fs.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/fs.spec.js deleted file mode 100644 index 3a70f2752c..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/fs.spec.js +++ /dev/null @@ -1,20 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var os = require('os'); -var tmpFile = path.join.bind(path, os.tmpdir()); - -describe('fs.readFile()', function(){ - describe('when the file exists', function(){ - it('should succeed', function(done){ - fs.writeFile(tmpFile('mocha'), 'wahoo', done) - }) - }) - - describe('when the file does not exist', function(){ - it('should fail', function(done){ - // uncomment - // fs.readFile(tmpFile('does-not-exist'), done); - done(); - }) - }) -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/glob/glob.sh b/tests/lib/mocha-3.1.0/test/acceptance/glob/glob.sh deleted file mode 100644 index 823ba07fb9..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/glob/glob.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -REL_SCRIPT_DIR="`dirname \"$0\"`" -SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`" - -cd $SCRIPT_DIR || { - echo Could not cd to $SCRIPT_DIR from `pwd` - exit 1 -} - -../../../bin/mocha -R json-stream ./*.js > /tmp/mocha-glob.txt || { - echo Globbing ./*.js in `pwd` failed. - exit 1 -} - -cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' || { - echo Globbing ./*.js in `pwd` should match glob.js with one test inside. - exit 1 -} - -../../../bin/mocha -R json-stream ./*-none.js 2> /tmp/mocha-glob.txt && { - echo Globbing './*-none.js' in `pwd` failed. - exit 1 -} - -cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || { - echo Globbing './*-none.js' in `pwd` should match no files and run no tests. - exit 1 -} - -../../../bin/mocha -R json-stream ./*.js ./*-none.js >& /tmp/mocha-glob.txt || { - echo Globbing ./*.js ./*-none.js in `pwd` failed. - exit 1 -} - -cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' && -cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || { - echo Globbing ./*.js ./*-none.js in `pwd` should match glob.js with one test inside and display one warning for the non-existing file. - exit 1 -} - -# Globbing in windows command-shell differs completely from unix-style globbing. -# In bash, the shell expands globs and passes the result to executables. -# In windows, the shell passes globs unexpanded, executables do expansion if they support it. -# Adding single-quotes around the glob below makes bash pass glob unexpanded, -# allowing us to test windows-style globbing in bash. -../../../bin/mocha -R json-stream './*.js' > /tmp/mocha-glob.txt || { - echo Globbing './*.js' in `pwd` failed. - exit 1 -} - -cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' || { - echo Globbing './*.js' in `pwd` should match glob.js with one test inside. - exit 1 -} - -../../../bin/mocha -R json-stream './*-none.js' 2> /tmp/mocha-glob.txt && { - echo Globbing './*-none.js' in `pwd` failed. - exit 1 -} - -cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || { - echo Globbing './*-none.js' in `pwd` should match no files and run no tests. - exit 1 -} - -echo Glob-test passed. diff --git a/tests/lib/mocha-3.1.0/test/acceptance/glob/glob.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/glob/glob.spec.js deleted file mode 100644 index 3029ae82ee..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/glob/glob.spec.js +++ /dev/null @@ -1,5 +0,0 @@ -describe('globbing test', function(){ - it('should find this test', function(){ - // see glob.sh for details - }) -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/globals.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/globals.spec.js deleted file mode 100644 index f8ef804b23..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/globals.spec.js +++ /dev/null @@ -1,41 +0,0 @@ -describe('global leaks', function(){ - before(function(){ - // uncomment to test - // foo = 'hey'; - // bar = 'hey'; - }) - - beforeEach(function(){ - // uncomment to test - // foo = 'bar' - }); - - it('should cause tests to fail', function(){ - // uncomment to test - // foo = 'bar'; - // bar = 'baz'; - // baz = 'raz'; - }); - - it('should pass when accepted', function(){ - global.okGlobalA = 1; - global.okGlobalB = 1; - global.okGlobalC = 1; - }) - - it('should pass with wildcard', function(){ - global.callback123 = 'foo'; - global.callback345 = 'bar'; - }); - - it('should pass when prefixed "mocha-"', function(){ - // Opera and IE do this for HTML element IDs anyway - // but to sure we can assert this in any browser, simulate it. - global['mocha-example'] = { nodeType: 1 }; - }); - - afterEach(function(){ - // uncomment to test - // foo = 'bar' - }); -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/http.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/http.spec.js deleted file mode 100644 index 43b8588508..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/http.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -var http = require('http'); - -var server = http.createServer(function(req, res){ - res.end('Hello World\n'); -}) - -server.listen(8888); - -describe('http', function(){ - it('should provide an example', function(done){ - http.get({ path: '/', port: 8888 }, function(res){ - expect(res).to.have.property('statusCode', 200); - done(); - }) - }) -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/interfaces/bdd.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/interfaces/bdd.spec.js deleted file mode 100644 index ba444c8f7f..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/interfaces/bdd.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -describe('integer primitives', function(){ - describe('arithmetic', function(){ - it('should add', function(){ - expect(1 + 1).to.equal(2); - expect(2 + 2).to.equal(4); - }) - - it('should subtract', function(){ - expect(1 - 1).to.equal(0); - expect(2 - 1).to.equal(1); - }) - }) -}) - -describe('integer primitives', function(){ - describe('arithmetic is not', function(){ - it('should add', function(){ - expect(1 + 1).not.to.equal(3); - expect(2 + 2).not.to.equal(5); - }) - }) -}) - -context('test suite', function(){ - beforeEach(function(){ - this.number = 5; - }) - - specify('share a property', function(){ - expect(this.number).to.equal(5); - }) -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/interfaces/exports.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/interfaces/exports.spec.js deleted file mode 100644 index 08db71200b..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/interfaces/exports.spec.js +++ /dev/null @@ -1,43 +0,0 @@ -var calls = []; - -exports.Array = { - before: function(){ - calls.push('before'); - }, - - after: function(){ - calls.push('after'); - expect(calls).to.eql([ - 'before' - , 'before each' - , 'one' - , 'after each' - , 'before each' - , 'two' - , 'after each' - , 'after']); - }, - - '#indexOf()': { - beforeEach: function(){ - calls.push('before each'); - }, - - afterEach: function(){ - calls.push('after each'); - }, - - 'should return -1 when the value is not present': function(){ - calls.push('one'); - expect([1,2,3].indexOf(5)).to.equal(-1); - expect([1,2,3].indexOf(0)).to.equal(-1); - }, - - 'should return the correct index when the value is present': function(){ - calls.push('two'); - expect([1,2,3].indexOf(1)).to.equal(0); - expect([1,2,3].indexOf(2)).to.equal(1); - expect([1,2,3].indexOf(3)).to.equal(2); - } - } -}; diff --git a/tests/lib/mocha-3.1.0/test/acceptance/interfaces/qunit.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/interfaces/qunit.spec.js deleted file mode 100644 index d452e769c5..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/interfaces/qunit.spec.js +++ /dev/null @@ -1,23 +0,0 @@ -function ok(expr, msg) { - if (!expr) throw new Error(msg); -} - -suite('integer primitives'); - -test('should add', function(){ - var number = 2 + 2; - ok(number == 4); -}); - -test('should decrement', function(){ - var number = 3; - ok(--number == 2); - ok(--number == 1); - ok(--number == 0); -}); - -suite('String'); - -test('#length', function(){ - ok('foo'.length == 3); -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/interfaces/tdd.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/interfaces/tdd.spec.js deleted file mode 100644 index 7ad079e36d..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/interfaces/tdd.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -suite('integer primitives', function(){ - suite('arithmetic', function(){ - var initialValue = 41; - - suiteSetup(function(done){ - expect(initialValue).to.eql(41); - initialValue += 1; - done(); - }); - - test('should add', function(){ - expect(initialValue).to.eql(42); - expect(1 + 1).to.equal(2); - expect(2 + 2).to.equal(4); - }); - - test('should subtract', function(){ - expect(initialValue).to.eql(42); - expect(1 - 1).to.equal(0); - expect(2 - 1).to.equal(1); - }); - - test.skip('should skip this test', function(){ - var zero = 0; - expect(zero).to.equal(1, 'this test should have been skipped'); - }); - - suite.skip('should skip this suite', function(){ - test('should skip this test', function(){ - var zero = 0; - expect(zero).to.equal(1, 'this test should have been skipped'); - }); - }); - - suiteTeardown(function(done){ - expect(initialValue).to.eql(42); - done(); - }); - }); -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/lookup-files.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/lookup-files.spec.js deleted file mode 100644 index 5d4a48d8af..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/lookup-files.spec.js +++ /dev/null @@ -1,90 +0,0 @@ -'use strict'; - -var utils = require('../../lib/utils'); -var fs = require('fs'); -var path = require('path'); -var os = require('os'); -var mkdirp = require('mkdirp'); -var rimraf = require('rimraf'); - -describe('lookupFiles', function() { - var tmpDir = path.join(os.tmpDir(), 'mocha-lookup-files'); - var existsSync = fs.existsSync; - var tmpFile = path.join.bind(path, tmpDir); - var symlinkSupported = false; - - (function testSymlinkSupport() { - makeTempDir(); - - fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow'); - try { - fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js')); - symlinkSupported = true; - } catch (ignored) { - // ignored - } finally { - removeTempDir(); - } - }()); - - beforeEach(function() { - makeTempDir(); - - fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow'); - if (symlinkSupported) { - fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js')); - } - }); - - (symlinkSupported ? it : it.skip)('should not choke on symlinks', function() { - expect(utils.lookupFiles(tmpDir, ['js'], false)) - .to - .contain(tmpFile('mocha-utils-link.js')) - .and - .contain(tmpFile('mocha-utils.js')) - .and - .have - .length(2); - expect(existsSync(tmpFile('mocha-utils-link.js'))) - .to - .be(true); - fs.renameSync(tmpFile('mocha-utils.js'), tmpFile('bob')); - expect(existsSync(tmpFile('mocha-utils-link.js'))) - .to - .be(false); - expect(utils.lookupFiles(tmpDir, ['js'], false)) - .to - .eql([]); - }); - - it('should accept a glob "path" value', function() { - var res = utils.lookupFiles(tmpFile('mocha-utils*'), ['js'], false) - .map(path.normalize.bind(path)); - - var expectedLength = 0; - var ex = expect(res) - .to - .contain(tmpFile('mocha-utils.js')); - expectedLength++; - - if (symlinkSupported) { - ex = ex.and - .contain(tmpFile('mocha-utils-link.js')); - expectedLength++; - } - - ex.and - .have - .length(expectedLength); - }); - - afterEach(removeTempDir); - - function makeTempDir() { - mkdirp.sync(tmpDir); - } - - function removeTempDir() { - rimraf.sync(tmpDir); - } -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/exit.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/exit.spec.js deleted file mode 100644 index 113e392300..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/exit.spec.js +++ /dev/null @@ -1,18 +0,0 @@ -describe('exit', function(){ - //note --bail works nicely in that it still allows an 'early exit' in an error scenario - it('should not exit even in error scenario if called with --no-exit', function(done){ - done(new Error('failure')); - }) - - it('should take a long time to exit if called with --no-exit', function(done){ - done(); - setTimeout(function() { - console.log('all done'); - }, 2500) - }) - - it('should kill all processes when SIGINT received', function () { - // uncomment to test - //while (true) {} - }); -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/many.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/many.spec.js deleted file mode 100644 index 26538bc66e..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/many.spec.js +++ /dev/null @@ -1,27 +0,0 @@ -// Useful for testing SIGINT handler -// use env.big_number to tune iterations so that you have time to ctrl+c - -describe('a load of tests', function(){ - it('should fail the first test', function(){ - throw new Error('this should appear in the summary'); - }) - - var iterations = (process.env.big_number || 1e7); - function work() { - var a = 0; - for(var i=0; i<iterations; ++i) { - a += i; - } - } - - function addTest() { - it('should pass test ' + i, function(){ - work(); - }) - } - - for(var i=0; i<500; ++i) { - addTest(); - } - -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/nontty.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/nontty.spec.js deleted file mode 100644 index 2372a660b9..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/nontty.spec.js +++ /dev/null @@ -1,9 +0,0 @@ -describe('tests for non-tty', function(){ - it('should pass', function(){ - - }) - - it('should fail', function(){ - throw new Error('oh noes') - }) -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/bdd-require.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/only/bdd-require.spec.js deleted file mode 100644 index 516dad7afa..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/bdd-require.spec.js +++ /dev/null @@ -1,18 +0,0 @@ -/*jshint node: true */ - -var mocha = require('../../../../lib/mocha'); - -var beforeEach = mocha.beforeEach; -var it = mocha.it; -var describe = mocha.describe; - -describe('it.only via require("mocha")', function() { - beforeEach(function() { - this.didRunBeforeEach = true; - }); - describe("nested within a describe/context", function() { - it.only('should run all enclosing beforeEach hooks', function() { - require('assert').equal(this.didRunBeforeEach, true); - }); - }); -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/bdd.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/only/bdd.spec.js deleted file mode 100644 index 7a33a74eac..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/bdd.spec.js +++ /dev/null @@ -1,125 +0,0 @@ -describe('should only run .only test in this bdd suite', function() { - it('should not run this test', function() { - (0).should.equal(1, 'this test should have been skipped'); - }); - it.only('should run this test', function() { - (0).should.equal(0, 'this .only test should run'); - }); - it('should run this test, not (includes the title of the .only test)', function() { - (0).should.equal(1, 'this test should have been skipped'); - }); -}); - -describe('should not run this suite', function() { - it('should not run this test', function() { - (true).should.equal(false); - }); - - it('should not run this test', function() { - (true).should.equal(false); - }); - - it('should not run this test', function() { - (true).should.equal(false); - }); -}); - -describe.only('should run all tests in this bdd suite', function() { - it('should run this test #1', function() { - (true).should.equal(true); - }); - - it('should run this test #2', function() { - (1).should.equal(1); - }); - - it('should run this test #3', function() { - ('foo').should.equal('foo'); - }); -}); - -describe('should run only suites that marked as `only`', function() { - describe.only('should run all this tdd suite', function() { - it('should run this test #1', function() { - (true).should.equal(true); - }); - - it('should run this test #2', function() { - (true).should.equal(true); - }); - }); - - describe('should not run this suite', function() { - it('should run this test', function() { - (true).should.equal(false); - }); - }); -}); - -// Nested situation -describe('should not run parent tests', function() { - it('should not run this test', function() { - (true).should.equal(false); - }); - describe('and not the child tests too', function() { - it('should not run this test', function() { - (true).should.equal(false); - }); - describe.only('but run all the tests in this suite', function() { - it('should run this test #1', function() { - (true).should.equal(true); - }); - it('should run this test #2', function() { - (true).should.equal(true); - }); - }); - }); -}); - -// mark test as `only` override the suite behavior -describe.only('should run only tests that marked as `only`', function() { - it('should not run this test #1', function() { - (false).should.equal(true); - }); - - it.only('should run this test #2', function() { - (true).should.equal(true); - }); - - it('should not run this test #3', function() { - (false).should.equal(true); - }); - - it.only('should run this test #4', function() { - (true).should.equal(true); - }); -}); - -describe.only('Should run only test cases that mark as only', function() { - it.only('should runt his test', function() { - (true).should.equal(true); - }); - - it('should not run this test', function() { - (false).should.equal(true); - }); - - describe('should not run this suite', function() { - it('should not run this test', function() { - (false).should.equal(true); - }); - }); -}); - -// Root Suite -it.only('#Root-Suite, should run this test-case #1', function() { - (true).should.equal(true); -}); - -it.only('#Root-Suite, should run this test-case #2', function() { - (true).should.equal(true); -}); - -it('#Root-Suite, should not run this test', function() { - (false).should.equal(true); -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/global/bdd.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/only/global/bdd.spec.js deleted file mode 100644 index e923876f84..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/global/bdd.spec.js +++ /dev/null @@ -1,12 +0,0 @@ -// Root-only test cases -it.only('#Root-Suite, should run this bdd test-case #1', function() { - (true).should.equal(true); -}); - -it('#Root-Suite, should not run this bdd test-case #2', function() { - (false).should.equal(true); -}); - -it('#Root-Suite, should not run this bdd test-case #3', function() { - (false).should.equal(true); -});
\ No newline at end of file diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/global/qunit.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/only/global/qunit.spec.js deleted file mode 100644 index 59ad72c3bf..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/global/qunit.spec.js +++ /dev/null @@ -1,12 +0,0 @@ -// Root-only test cases -test.only('#Root-Suite, should run this qunit test-case #1', function() { - (true).should.equal(true); -}); - -test('#Root-Suite, should not run this qunit test-case #2', function() { - (false).should.equal(true); -}); - -test('#Root-Suite, should not run this qunit test-case #3', function() { - (false).should.equal(true); -});
\ No newline at end of file diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/global/tdd.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/only/global/tdd.spec.js deleted file mode 100644 index 08d456848b..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/global/tdd.spec.js +++ /dev/null @@ -1,12 +0,0 @@ -// Root-only test cases -test.only('#Root-Suite, should run this tdd test-case #1', function() { - (true).should.equal(true); -}); - -test('#Root-Suite, should not run this tdd test-case #2', function() { - (false).should.equal(true); -}); - -test('#Root-Suite, should not run this tdd test-case #3', function() { - (false).should.equal(true); -});
\ No newline at end of file diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/qunit.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/only/qunit.spec.js deleted file mode 100644 index 1248adeba7..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/qunit.spec.js +++ /dev/null @@ -1,73 +0,0 @@ -// Root Suite -test.only('#Root-Suite, should run this test-case #1', function() { - (true).should.equal(true); -}); - -test.only('#Root-Suite, should run this test-case #2', function() { - (true).should.equal(true); -}); - -test('#Root-Suite, should not run this test', function() { - (false).should.equal(true); -}); - -suite('should only run .only test in this qunit suite'); - -test('should not run this test', function() { - (0).should.equal(1, 'this test should have been skipped'); -}); -test.only('should run this test', function() { - (0).should.equal(0, 'this .only test should run'); -}); -test('should run this test, not (includes the title of the .only test)', function() { - (0).should.equal(1, 'this test should have been skipped'); -}); - -// Mark suite -suite.only('should run all tests in this suite'); - -test('should run this test #1', function() { - (true).should.equal(true); -}); - -test('should run this test #2', function() { - (true).should.equal(true); -}); - -test('should run this test #3', function() { - (true).should.equal(true); -}); - -// Unmark this suite -suite('should not run any of this suite\'s tests'); - -test('should not run this test', function() { - (false).should.equal(true); -}); - -test('should not run this test', function() { - (false).should.equal(true); -}); - -test('should not run this test', function() { - (false).should.equal(true); -}); - -// Mark test as `only` override the suite behavior -suite.only('should run only tests that marked as `only`'); - -test('should not run this test #1', function() { - (false).should.equal(true); -}); - -test.only('should not run this test #2', function() { - (true).should.equal(true); -}); - -test('should not run this test #3', function() { - (false).should.equal(true); -}); - -test.only('should not run this test #4', function() { - (true).should.equal(true); -});
\ No newline at end of file diff --git a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/tdd.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/misc/only/tdd.spec.js deleted file mode 100644 index 7e37e7a3b3..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/misc/only/tdd.spec.js +++ /dev/null @@ -1,125 +0,0 @@ -suite('should only run .only test in this tdd suite', function() { - test('should not run this test', function() { - (0).should.equal(1, 'this test should have been skipped'); - }); - test.only('should run this test', function() { - (0).should.equal(0, 'this .only test should run'); - }); - test('should run this test, not (includes the title of the .only test)', function() { - (0).should.equal(1, 'this test should have been skipped'); - }); -}); - -suite('should not run this suite', function() { - test('should not run this test', function() { - (true).should.equal(false); - }); - - test('should not run this test', function() { - (true).should.equal(false); - }); - - test('should not run this test', function() { - (true).should.equal(false); - }); -}); - -suite.only('should run all tests in this tdd suite', function() { - test('should run this test #1', function() { - (true).should.equal(true); - }); - - test('should run this test #2', function() { - (1).should.equal(1); - }); - - test('should run this test #3', function() { - ('foo').should.equal('foo'); - }); -}); - -suite('should run only suites that marked as `only`', function() { - suite.only('should run all this tdd suite', function() { - test('should run this test #1', function() { - (true).should.equal(true); - }); - - test('should run this test #2', function() { - (true).should.equal(true); - }); - }); - - suite('should not run this suite', function() { - test('should not run this test', function() { - (true).should.equal(false); - }); - }); -}); - -// Nested situation -suite('should not run parent tests', function() { - test('should not run this test', function() { - (true).should.equal(false); - }); - suite('and not the child tests too', function() { - test('should not run this test', function() { - (true).should.equal(false); - }); - suite.only('but run all the tests in this suite', function() { - test('should run this test #1', function() { - (true).should.equal(true); - }); - test('should run this test #2', function() { - (true).should.equal(true); - }); - }); - }); -}); - -// mark test as `only` override the suite behavior -suite.only('should run only tests that marked as `only`', function() { - test('should not run this test #1', function() { - (false).should.equal(true); - }); - - test.only('should run this test #2', function() { - (true).should.equal(true); - }); - - test('should not run this test #3', function() { - (false).should.equal(true); - }); - - test.only('should run this test #4', function() { - (true).should.equal(true); - }); -}); - -suite.only('Should run only test cases that mark as only', function() { - test.only('should runt his test', function() { - (true).should.equal(true); - }); - - test('should not run this test', function() { - (false).should.equal(true); - }); - - suite('should not run this suite', function() { - test('should not run this test', function() { - (false).should.equal(true); - }); - }); -}); - -// Root Suite -test.only('#Root-Suite, should run this test-case #1', function() { - (true).should.equal(true); -}); - -test.only('#Root-Suite, should run this test-case #2', function() { - (true).should.equal(true); -}); - -test('#Root-Suite, should not run this test', function() { - (false).should.equal(true); -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/overspecified-async.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/overspecified-async.spec.js deleted file mode 100644 index 2844920379..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/overspecified-async.spec.js +++ /dev/null @@ -1,8 +0,0 @@ -describe('overspecified asynchronous resolution method', function() { - it('should fail when multiple methods are used', function(done) { - setTimeout(done, 0); - - // uncomment - // return { then: function() {} }; - }); -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/require/a.js b/tests/lib/mocha-3.1.0/test/acceptance/require/a.js deleted file mode 100644 index 592d827449..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/require/a.js +++ /dev/null @@ -1,2 +0,0 @@ -global.required = (global.required || []) -global.required.push('a.js') diff --git a/tests/lib/mocha-3.1.0/test/acceptance/require/b.coffee b/tests/lib/mocha-3.1.0/test/acceptance/require/b.coffee deleted file mode 100644 index 045cc7591b..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/require/b.coffee +++ /dev/null @@ -1,2 +0,0 @@ -global.required ?= [] -global.required.push 'b.coffee' diff --git a/tests/lib/mocha-3.1.0/test/acceptance/require/c.js b/tests/lib/mocha-3.1.0/test/acceptance/require/c.js deleted file mode 100644 index 4e681373a1..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/require/c.js +++ /dev/null @@ -1,2 +0,0 @@ -global.required = (global.required || []) -global.required.push('c.js') diff --git a/tests/lib/mocha-3.1.0/test/acceptance/require/d.coffee b/tests/lib/mocha-3.1.0/test/acceptance/require/d.coffee deleted file mode 100644 index d5ebbf60ed..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/require/d.coffee +++ /dev/null @@ -1,2 +0,0 @@ -global.required ?= [] -global.required.push 'd.coffee' diff --git a/tests/lib/mocha-3.1.0/test/acceptance/require/require.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/require/require.spec.js deleted file mode 100644 index 22570e62ff..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/require/require.spec.js +++ /dev/null @@ -1,9 +0,0 @@ -describe('require test', function(){ - it('should require args in order', function(){ - var req = global.required; - expect(req.indexOf('a.js')).to.equal(0); - expect(req.indexOf('b.coffee')).to.equal(1); - expect(req.indexOf('c.js')).to.equal(2); - expect(req.indexOf('d.coffee')).to.equal(3); - }) -}); diff --git a/tests/lib/mocha-3.1.0/test/acceptance/required-tokens.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/required-tokens.spec.js deleted file mode 100644 index 6944cee40c..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/required-tokens.spec.js +++ /dev/null @@ -1,10 +0,0 @@ -var assert = require('assert'); -var describe = require('../..').describe; -var it = require('../..').it; - -describe('using imported describe', function () { - it('using imported it', function (done) { - assert.ok(true); - done(); - }) -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/root.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/root.spec.js deleted file mode 100644 index 037e6a328a..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/root.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -var calls = []; - -before(function(){ - calls.push('before'); -}) - -describe('root', function(){ - it('should be a valid suite', function(){ - expect(calls).to.eql(['before']); - }) -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/test.coffee b/tests/lib/mocha-3.1.0/test/acceptance/test.coffee deleted file mode 100644 index b8e309f515..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/test.coffee +++ /dev/null @@ -1,6 +0,0 @@ - -obj = foo: 'bar' - -describe 'coffeescript', -> - it 'should work', -> - expect(obj).to.eql foo: 'bar' diff --git a/tests/lib/mocha-3.1.0/test/acceptance/test.foo b/tests/lib/mocha-3.1.0/test/acceptance/test.foo deleted file mode 100644 index d00491fd7e..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/test.foo +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/lib/mocha-3.1.0/test/acceptance/throw.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/throw.spec.js deleted file mode 100644 index 46cfbad6ad..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/throw.spec.js +++ /dev/null @@ -1,108 +0,0 @@ -var Suite = require('../../lib/suite'); -var Test = require('../../lib/test'); -var Runner = require('../../lib/runner'); - -describe('a test that throws', function () { - var suite, runner; - - beforeEach(function(){ - suite = new Suite('Suite', 'root'); - runner = new Runner(suite); - }) - - describe('undefined', function (){ - it('should not pass if throwing sync and test is sync', function(done) { - var test = new Test('im sync and throw undefined sync', function(){ - throw undefined; - }); - suite.addTest(test); - runner = new Runner(suite); - runner.on('end', function(){ - expect(runner.failures).to.equal(1); - expect(test.state).to.equal('failed'); - done(); - }); - runner.run(); - }) - - it('should not pass if throwing sync and test is async', function(done){ - var test = new Test('im async and throw undefined sync', function(done2){ - throw undefined; - process.nexTick(done2); - }); - suite.addTest(test); - runner = new Runner(suite); - runner.on('end', function(){ - expect(runner.failures).to.equal(1); - expect(test.state).to.equal('failed'); - done(); - }); - runner.run(); - }); - - it('should not pass if throwing async and test is async', function(done){ - var test = new Test('im async and throw undefined async', function(done2){ - process.nexTick(function(){ - throw undefined; - done2(); - }); - }); - suite.addTest(test); - runner = new Runner(suite); - runner.on('end', function(){ - expect(runner.failures).to.equal(1); - expect(test.state).to.equal('failed'); - done(); - }); - runner.run(); - }) - }) - - describe('null', function (){ - it('should not pass if throwing sync and test is sync', function(done) { - var test = new Test('im sync and throw null sync', function(){ - throw null; - }); - suite.addTest(test); - runner = new Runner(suite); - runner.on('end', function(){ - expect(runner.failures).to.equal(1); - expect(test.state).to.equal('failed'); - done(); - }); - runner.run(); - }) - - it('should not pass if throwing sync and test is async', function(done){ - var test = new Test('im async and throw null sync', function(done2){ - throw null; - process.nexTick(done2); - }); - suite.addTest(test); - runner = new Runner(suite); - runner.on('end', function(){ - expect(runner.failures).to.equal(1); - expect(test.state).to.equal('failed'); - done(); - }); - runner.run(); - }); - - it('should not pass if throwing async and test is async', function(done){ - var test = new Test('im async and throw null async', function(done2){ - process.nexTick(function(){ - throw null; - done2(); - }); - }); - suite.addTest(test); - runner = new Runner(suite); - runner.on('end', function(){ - expect(runner.failures).to.equal(1); - expect(test.state).to.equal('failed'); - done(); - }); - runner.run(); - }) - }) -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/timeout.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/timeout.spec.js deleted file mode 100644 index f61c3ba566..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/timeout.spec.js +++ /dev/null @@ -1,79 +0,0 @@ -describe('timeouts', function(){ - beforeEach(function(done){ - // uncomment - // setTimeout(done, 3000); - done(); - }) - - it('should error on timeout', function(done){ - // uncomment - // setTimeout(done, 3000); - done(); - }) - - it('should allow overriding per-test', function(done){ - this.timeout(1000); - setTimeout(function(){ - done(); - }, 300); - }) - - describe('disabling', function(){ - it('should allow overriding per-test', function(done){ - this.enableTimeouts(false); - this.timeout(1); - setTimeout(done, 2); - }); - - it('should work with timeout(0)', function(done) { - this.timeout(0); - setTimeout(done, 1); - }) - - describe('using beforeEach', function() { - beforeEach(function () { - this.timeout(0); - }) - - it('should work with timeout(0)', function(done) { - setTimeout(done, 1); - }) - }) - - describe('using before', function() { - before(function () { - this.timeout(0); - }) - - it('should work with timeout(0)', function(done) { - setTimeout(done, 1); - }) - }) - - describe('using enableTimeouts(false)', function() { - this.timeout(4); - - it('should suppress timeout(4)', function(done) { - // The test is in the before() call. - this.enableTimeouts(false); - setTimeout(done, 50); - }) - }) - - describe('suite-level', function() { - this.timeout(0); - - it('should work with timeout(0)', function(done) { - setTimeout(done, 1); - }) - - describe('nested suite', function () { - it('should work with timeout(0)', function(done) { - setTimeout(done, 1); - }) - - }) - }) - }); - -}) diff --git a/tests/lib/mocha-3.1.0/test/acceptance/utils.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/utils.spec.js deleted file mode 100644 index cab0f42b01..0000000000 --- a/tests/lib/mocha-3.1.0/test/acceptance/utils.spec.js +++ /dev/null @@ -1,406 +0,0 @@ -var utils = require('../../lib/utils'); -var toISOString = require('../../lib/to-iso-string'); -var JSON = require('json3'); - -describe('lib/utils', function () { - describe('clean', function () { - it("should format a single line test function", function () { - var fn = [ - "function () {" - , " var a = 1;" - , "}" - ].join("\n"); - expect(utils.clean(fn)).to.equal("var a = 1;"); - }); - - it("should format a multi line test indented with spaces", function () { - // and no new lines after curly braces, shouldn't matter - var fn = [ - "function(){ var a = 1;" - , " var b = 2;" // this one has more spaces - , " var c = 3; }" - ].join("\n"); - expect(utils.clean(fn)).to.equal("var a = 1;\n var b = 2;\nvar c = 3;"); - }); - - it("should format a multi line test indented with tabs", function () { - var fn = [ - "function (arg1, arg2) {" - , "\tif (true) {" - , "\t\tvar a = 1;" - , "\t}" - , "}" - ].join("\n"); - expect(utils.clean(fn)).to.equal("if (true) {\n\tvar a = 1;\n}"); - }); - - it("should format functions saved in windows style - spaces", function () { - var fn = [ - "function (one) {" - , " do {" - , ' "nothing";' - , " } while (false);" - , ' }' - ].join("\r\n"); - expect(utils.clean(fn)).to.equal('do {\n "nothing";\n} while (false);'); - }); - - it("should format functions saved in windows style - tabs", function () { - var fn = [ - "function ( ) {" - , "\tif (false) {" - , "\t\tvar json = {" - , '\t\t\tone : 1' - , '\t\t};' - , "\t}" - , "}" - ].join("\r\n"); - expect(utils.clean(fn)).to.equal("if (false) {\n\tvar json = {\n\t\tone : 1\n\t};\n}"); - }); - - it("should format es6 arrow functions", function () { - var fn = [ - "() => {", - " var a = 1;", - "}" - ].join("\n"); - expect(utils.clean(fn)).to.equal("var a = 1;"); - }); - - it("should format es6 arrow functions with implicit return", function () { - var fn = "() => foo()"; - expect(utils.clean(fn)).to.equal("foo()"); - }); - }); - - describe('stringify', function(){ - - var stringify = utils.stringify; - - it('should return an object representation of a string created with a String constructor', function() { - expect(stringify(new String('foo'))).to.equal('{\n "0": "f"\n "1": "o"\n "2": "o"\n}'); - }); - - it('should return Buffer with .toJSON representation', function() { - expect(stringify(new Buffer([0x01]))).to.equal('[\n 1\n]'); - expect(stringify(new Buffer([0x01, 0x02]))).to.equal('[\n 1\n 2\n]'); - - expect(stringify(new Buffer('ABCD'))).to.equal('[\n 65\n 66\n 67\n 68\n]'); - }); - - it('should return Date object with .toISOString() + string prefix', function() { - expect(stringify(new Date(0))).to.equal('[Date: ' + shimToISOString(new Date(0)) + ']'); - - var date = new Date(); // now - expect(stringify(date)).to.equal('[Date: ' + shimToISOString(date) + ']'); - - function shimToISOString(date) { - if (date.toISOString) { - return date.toISOString(); - } else { - return toISOString(date); - } - } - }); - - it('should return invalid Date object with .toString() + string prefix', function() { - expect(stringify(new Date(''))).to.equal('[Date: ' + new Date('').toString() + ']'); - }); - - describe('#Number', function() { - it('should show the handle -0 situations', function() { - expect(stringify(-0)).to.eql('-0'); - expect(stringify(0)).to.eql('0'); - expect(stringify('-0')).to.eql('"-0"'); - }); - - it('should work well with `NaN` and `Infinity`', function() { - expect(stringify(NaN)).to.equal('NaN'); - expect(stringify(Infinity)).to.equal('Infinity'); - expect(stringify(-Infinity)).to.equal('-Infinity'); - }); - - it('floats and ints', function() { - expect(stringify(1)).to.equal('1'); - expect(stringify(1.2)).to.equal('1.2'); - expect(stringify(1e9)).to.equal('1000000000'); - }); - }); - - describe('canonicalize example', function() { - it('should represent the actual full result', function() { - var expected = { - str: 'string', - int: 90, - float: 9.99, - boolean: false, - nil: null, - undef: undefined, - regex: /^[a-z|A-Z]/, - date: new Date(0), - func: function() {}, - infi: Infinity, - nan: NaN, - zero: -0, - buffer: new Buffer([0x01, 0x02]), - array: [1,2,3], - empArr: [], - matrix: [[1], [2,3,4] ], - object: { a: 1, b: 2 }, - canObj: { a: { b: 1, c: 2 }, b: {} }, - empObj: {} - }; - expected.circular = expected; // Make `Circular` situation - var actual = ['{' - , ' "array": [' - , ' 1' - , ' 2' - , ' 3' - , ' ]' - , ' "boolean": false' - , ' "buffer": [Buffer: [' - , ' 1' - , ' 2' - , ' ]]' - , ' "canObj": {' - , ' "a": {' - , ' "b": 1' - , ' "c": 2' - , ' }' - , ' "b": {}' - , ' }' - , ' "circular": [Circular]' - , ' "date": [Date: 1970-01-01T00:00:00.000Z]' - , ' "empArr": []' - , ' "empObj": {}' - , ' "float": 9.99' - , ' "func": [Function]' - , ' "infi": Infinity' - , ' "int": 90' - , ' "matrix": [' - , ' [' - , ' 1' - , ' ]' - , ' [' - , ' 2' - , ' 3' - , ' 4' - , ' ]' - , ' ]' - , ' "nan": NaN' - , ' "nil": [null]' - , ' "object": {' - , ' "a": 1' - , ' "b": 2' - , ' }' - , ' "regex": /^[a-z|A-Z]/' - , ' "str": "string"' - , ' "undef": [undefined]' - , ' "zero": -0' - , '}'].join('\n'); - expect(stringify(expected)).to.equal(actual); - }); - }); - - it('should canonicalize the object', function(){ - var travis = { name: 'travis', age: 24 }; - var travis2 = { age: 24, name: 'travis' }; - - expect(stringify(travis)).to.equal(stringify(travis2)); - }); - - it('should handle circular structures in objects', function(){ - var travis = { name: 'travis' }; - travis.whoami = travis; - - expect(stringify(travis)).to.equal('{\n "name": "travis"\n "whoami": [Circular]\n}'); - }); - - it('should handle circular structures in arrays', function(){ - var travis = ['travis']; - travis.push(travis); - - expect(stringify(travis)).to.equal('[\n "travis"\n [Circular]\n]'); - }); - - it('should handle circular structures in functions', function(){ - var travis = function () {}; - travis.fn = travis; - - expect(stringify(travis)).to.equal('{\n "fn": [Circular]\n}'); - }); - - - it('should handle various non-undefined, non-null, non-object, non-array, non-date, and non-function values', function () { - var regexp = new RegExp("(?:)"), - regExpObj = { regexp: regexp }, - regexpString = '/(?:)/'; - - expect(stringify(regExpObj)).to.equal('{\n "regexp": ' + regexpString + '\n}'); - expect(stringify(regexp)).to.equal(regexpString); - - var number = 1, - numberObj = { number: number }, - numberString = '1'; - - expect(stringify(numberObj)).to.equal('{\n "number": ' + number + '\n}'); - expect(stringify(number)).to.equal(numberString); - - var boolean = false, - booleanObj = { boolean: boolean }, - booleanString = 'false'; - - expect(stringify(booleanObj)).to.equal('{\n "boolean": ' + boolean + '\n}'); - expect(stringify(boolean)).to.equal(booleanString); - - var string = 'sneepy', - stringObj = { string: string }; - - expect(stringify(stringObj)).to.equal('{\n "string": "' + string + '"\n}'); - expect(stringify(string)).to.equal(JSON.stringify(string)); - - var nullValue = null, - nullObj = { 'null': null }, - nullString = '[null]'; - - expect(stringify(nullObj)).to.equal('{\n "null": [null]\n}'); - expect(stringify(nullValue)).to.equal(nullString); - }); - - it('should handle arrays', function () { - var array = ['dave', 'dave', 'dave', 'dave'], - arrayObj = {array: array}, - arrayString = ' "dave"\n "dave"\n "dave"\n "dave"' - - expect(stringify(arrayObj)).to.equal('{\n "array": [\n' + arrayString + '\n ]\n}'); - expect(stringify(array)).to.equal('[' + arrayString.replace(/\s+/g, '\n ') + '\n]'); - }); - - it('should handle functions', function () { - var fn = function() {}, - fnObj = {fn: fn}, - fnString = '[Function]'; - - expect(stringify(fnObj)).to.equal('{\n "fn": ' + fnString + '\n}'); - expect(stringify(fn)).to.equal('[Function]'); - }); - - it('should handle empty objects', function () { - expect(stringify({})).to.equal('{}'); - expect(stringify({foo: {}})).to.equal('{\n "foo": {}\n}'); - }); - - it('should handle empty arrays', function () { - expect(stringify([])).to.equal('[]'); - expect(stringify({foo: []})).to.equal('{\n "foo": []\n}'); - }); - - it('should handle non-empty arrays', function () { - expect(stringify(['a', 'b', 'c'])).to.equal('[\n "a"\n "b"\n "c"\n]') - }); - - it('should handle empty functions (with no properties)', function () { - expect(stringify(function(){})).to.equal('[Function]'); - expect(stringify({foo: function() {}})).to.equal('{\n "foo": [Function]\n}'); - expect(stringify({foo: function() {}, bar: 'baz'})).to.equal('{\n "bar": "baz"\n "foo": [Function]\n}'); - }); - - it('should handle functions w/ properties', function () { - var fn = function(){}; - fn.bar = 'baz'; - expect(stringify(fn)).to.equal('{\n "bar": "baz"\n}'); - expect(stringify({foo: fn})).to.equal('{\n "foo": {\n "bar": "baz"\n }\n}'); - }); - - it('should handle undefined values', function () { - expect(stringify({foo: undefined})).to.equal('{\n "foo": [undefined]\n}'); - expect(stringify({foo: 'bar', baz: undefined})).to.equal('{\n "baz": [undefined]\n "foo": "bar"\n}'); - expect(stringify()).to.equal('[undefined]'); - }); - - it('should recurse', function () { - expect(stringify({foo: {bar: {baz: {quux: {herp: 'derp'}}}}})).to.equal('{\n "foo": {\n "bar": {\n "baz": {\n "quux": {\n "herp": "derp"\n }\n }\n }\n }\n}'); - }); - - it('might get confusing', function () { - expect(stringify(null)).to.equal('[null]'); - }); - - it('should not freak out if it sees a primitive twice', function () { - expect(stringify({foo: null, bar: null})).to.equal('{\n "bar": [null]\n "foo": [null]\n}'); - expect(stringify({foo: 1, bar: 1})).to.equal('{\n "bar": 1\n "foo": 1\n}'); - }); - - it('should stringify dates', function () { - var date = new Date(0); - expect(stringify(date)).to.equal('[Date: 1970-01-01T00:00:00.000Z]'); - expect(stringify({date: date})).to.equal('{\n "date": [Date: 1970-01-01T00:00:00.000Z]\n}'); - }); - - it('should handle object without an Object prototype', function () { - var a; - if (Object.create) { - a = Object.create(null); - } else { - a = {}; - } - a.foo = 1; - - expect(stringify(a)).to.equal('{\n "foo": 1\n}'); - }); - - // In old version node.js, Symbol is not available by default. - if (typeof global.Symbol === 'function') { - it('should handle Symbol', function () { - var symbol = Symbol('value'); - expect(stringify(symbol)).to.equal('Symbol(value)'); - expect(stringify({symbol: symbol})).to.equal('{\n "symbol": Symbol(value)\n}') - }); - } - - it('should handle length properties that cannot be coerced to a number', function () { - expect(stringify({length: {nonBuiltinProperty: 0}})).to.equal('{\n "length": {\n "nonBuiltinProperty": 0\n }\n}'); - expect(stringify({length: "a string where length should be"})).to.equal('{\n "length": "a string where length should be"\n}'); - }); - }); - - describe('type', function () { - var type = utils.type; - var toString = Object.prototype.toString; - - beforeEach(function() { - // some JS engines such as PhantomJS 1.x exhibit this behavior - Object.prototype.toString = function() { - if (this === global) { - return '[object DOMWindow]'; - } - return toString.call(this); - }; - }); - - it('should recognize various types', function () { - expect(type({})).to.equal('object'); - expect(type([])).to.equal('array'); - expect(type(1)).to.equal('number'); - expect(type(Infinity)).to.equal('number'); - expect(type(null)).to.equal('null'); - expect(type(undefined)).to.equal('undefined'); - expect(type(new Date())).to.equal('date'); - expect(type(/foo/)).to.equal('regexp'); - expect(type('type')).to.equal('string'); - expect(type(global)).to.equal('domwindow'); - expect(type(true)).to.equal('boolean'); - }); - - describe('when toString on null or undefined stringifies window', function () { - it('should recognize null and undefined', function () { - expect(type(null)).to.equal('null'); - expect(type(undefined)).to.equal('undefined'); - }); - }); - - afterEach(function () { - Object.prototype.toString = toString; - }); - }); -}); |