diff --git a/.eslintrc.json b/.eslintrc.json index 7fae8d3c0e..7fdd614117 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -22,6 +22,7 @@ "env": { "node": true, "browser": true, - "amd": true + "amd": true, + "jasmine": true } } diff --git a/jasmine.json b/jasmine.json new file mode 100644 index 0000000000..8d1be919d1 --- /dev/null +++ b/jasmine.json @@ -0,0 +1,11 @@ +{ + "spec_dir": "test", + "spec_files": [ + "**/*-spec.js" + ], + "helpers": [ + "helpers/**/*.js" + ], + "stopSpecOnExpectationFailure": false, + "random": true +} diff --git a/package-lock.json b/package-lock.json index 311e5da5ca..2e48745bed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -857,6 +857,20 @@ "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", "dev": true }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.3.3", + "path-is-absolute": "1.0.1" + } + }, "glob-to-regexp": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz", @@ -1130,6 +1144,22 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, + "jasmine": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.1.0.tgz", + "integrity": "sha1-K9Wf1+xuwOistk4J9Fpo7SrRlSo=", + "dev": true, + "requires": { + "glob": "7.1.2", + "jasmine-core": "3.1.0" + } + }, + "jasmine-core": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.1.0.tgz", + "integrity": "sha1-pHheE11d9lAk38kiSVPfWFvSdmw=", + "dev": true + }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", @@ -1271,6 +1301,15 @@ "integrity": "sha1-5md4PZLonb00KBi1IwudYqZyrRg=", "dev": true }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "1.1.8" + } + }, "mkdirp": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", diff --git a/package.json b/package.json index 11ab79ec2f..b8a4702ee0 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,18 @@ "eslint-plugin-standard": "^3.0.1", "front-matter": "^2.3.0", "glob-to-regexp": "0.3.0", + "jasmine": "^3.1.0", "markdown": "*", "markdown-it": "*", "showdown": "*", "uglify-js": "^3.3.10" }, "scripts": { - "test": "node test", + "test": "jasmine --config=jasmine.json", + "test:unit": "npm test -- test/unit/**/*-spec.js", + "test:specs": "npm test -- test/specs/**/*-spec.js", + "test:integration": "npm test -- test/integration/**/*-spec.js", + "test:old": "node test", "test:lint": "eslint lib/marked.js test/index.js", "bench": "node test --bench", "lint": "eslint --fix lib/marked.js test/index.js", diff --git a/test/integration/marked-spec.js b/test/integration/marked-spec.js new file mode 100644 index 0000000000..6d3b9ee78c --- /dev/null +++ b/test/integration/marked-spec.js @@ -0,0 +1,5 @@ +var marked = require('../../marked.min.js'); + +it('should run the test', function () { + expect(marked('Hello World!')).toBe('

Hello World!

\n'); +}); diff --git a/test/specs/specs-spec.js b/test/specs/specs-spec.js new file mode 100644 index 0000000000..65526c863c --- /dev/null +++ b/test/specs/specs-spec.js @@ -0,0 +1,12 @@ +var specTests = require('../'); + +it('should run spec tests', function () { + // hide output + spyOn(console, 'log'); + if (!specTests({stop: true})) { + // if tests fail rerun tests and show output + console.log.and.callThrough(); + specTests(); + fail(); + } +}); diff --git a/test/unit/marked-spec.js b/test/unit/marked-spec.js new file mode 100644 index 0000000000..83f4fb57a0 --- /dev/null +++ b/test/unit/marked-spec.js @@ -0,0 +1,7 @@ +var marked = require('../../lib/marked.js'); + +it('should run the test', function () { + spyOn(marked, 'parse').and.callThrough(); + marked.parse('Hello World!'); + expect(marked.parse).toHaveBeenCalled(); +});