literate-jasmine
Advanced tools
Comparing version 0.0.15 to 0.0.16
{ | ||
"name": "literate-jasmine", | ||
"description": "write tests in markdown that are parsed to specification files to run with jasmine-node", | ||
"version": "0.0.15", | ||
"description": "write tests in markdown that are parsed and then run directly in jasmine", | ||
"version": "0.0.16", | ||
"bin": { | ||
@@ -27,4 +27,4 @@ "literate-jasmine": "./bin/literate-jasmine" | ||
"scripts": { | ||
"test": "jasmine-node --forceexit spec" | ||
"test": "jasmine-node --forceexit spec && ./bin/literate-jasmine README.md" | ||
} | ||
} |
@@ -58,9 +58,5 @@ # literate-jasmine [![Build Status](https://travis-ci.org/cymen/literate-jasmine.png?branch=master)](https://travis-ci.org/cymen/literate-jasmine) | ||
Which is then written to disk as `FILENAME_spec.js`. Take a look at `README_spec.js` | ||
as an example -- it is generated using this file (`README.md`) as input! | ||
Which is then uses the Jasmine `describe`, `it` and `beforeEach` to setup the | ||
tests and then run them. | ||
The command `literate-jasmine` is used to convert the markdown to JavaScript | ||
(assuming you ran `npm install -g literate-jasmine`). After conversion, it | ||
also runs `jasmine-node` to execute the tests: | ||
`literate-jasmine README.md` | ||
@@ -67,0 +63,0 @@ |
@@ -78,12 +78,21 @@ var parser = require('../src/parser'), | ||
it('parses out the name', function() { | ||
var it = parser.parseIt(tree, 1); | ||
var parsedIt = parser.parseIt(tree, 1); | ||
expect(it.name).toBe('it 1'); | ||
expect(parsedIt.name).toBe('it 1'); | ||
}); | ||
it('parses out the code', function() { | ||
var it = parser.parseIt(tree, 1); | ||
var parsedIt = parser.parseIt(tree, 1); | ||
expect(it.code).toBe('var x = 10;\nconsole.log("x", x);\nexpect(x).toBe(10);'); | ||
expect(parsedIt.code).toBe('var x = 10;\nconsole.log("x", x);\nexpect(x).toBe(10);'); | ||
}); | ||
it('adds a function call to run the code', function() { | ||
spyOn(console, 'log'); | ||
var parsedIt = parser.parseIt(tree, 1); | ||
parsedIt.fn(); | ||
expect(console.log).toHaveBeenCalledWith('x', 10); | ||
}); | ||
}); | ||
@@ -116,18 +125,36 @@ | ||
it('parses the describe name', function() { | ||
var describe = parser.parseDescribe(tree, 1); | ||
var parsedDescribe = parser.parseDescribe(tree, 1); | ||
expect(describe.name).toBe('can set a variable to a number'); | ||
expect(parsedDescribe.name).toBe('can set a variable to a number'); | ||
}); | ||
it('parsers out the it blocks', function() { | ||
var describe = parser.parseDescribe(tree, 1); | ||
var parsedDescribe = parser.parseDescribe(tree, 1); | ||
expect(describe.it.length).toBe(1); | ||
expect(parsedDescribe.it.length).toBe(1); | ||
}); | ||
it('parses out any code blocks before the it as a beforeEach', function() { | ||
var describe = parser.parseDescribe(tree, 1); | ||
var parsedDescribe = parser.parseDescribe(tree, 1); | ||
expect(describe.beforeEach).toContain('someGlobal = 42;'); | ||
expect(parsedDescribe.beforeEach).toContain('someGlobal = 42;'); | ||
}); | ||
it('adds a function call to run the beforeEach', function() { | ||
var parsedDescribe = parser.parseDescribe(tree, 1); | ||
someGlobal = 21; | ||
parsedDescribe.beforeEachFn(); | ||
expect(someGlobal).toBe(42); | ||
}); | ||
it('adds a function call to run each it within the describe', function() { | ||
var itSpy = jasmine.createSpy('it'), | ||
parsedDescribe = parser.parseDescribe(tree, 1); | ||
parsedDescribe.fn(itSpy); | ||
expect(itSpy).toHaveBeenCalledWith('it 1', jasmine.any(Function)); | ||
}); | ||
}); | ||
@@ -181,3 +208,24 @@ | ||
}); | ||
it('adds a function to call for global setup', function() { | ||
someOtherRealGlobal = -5; | ||
var result = parser.parse(text); | ||
result.globalFn(); | ||
expect(someOtherRealGlobal).toBe(500); | ||
}); | ||
it('adds a function call to run each describe within the root describe', function() { | ||
var describeSpy = jasmine.createSpy('describe').andCallFake(function(name, describeFn) { | ||
describeFn(function() {}); | ||
}); | ||
var result = parser.parse(text); | ||
result.fn(describeSpy); | ||
expect(describeSpy).toHaveBeenCalledWith('my title here', jasmine.any(Function)); | ||
expect(describeSpy).toHaveBeenCalledWith('can set a variable to a number', jasmine.any(Function)); | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
require('jasmine-node'); | ||
var markdown = require('markdown').markdown, | ||
@@ -21,2 +23,5 @@ ROOT_LEVEL = 1, | ||
complete.global = parser.parseCodeBlocks(tree, 1); | ||
complete.globalFn = function(then) { | ||
eval(complete.global); | ||
}; | ||
@@ -30,2 +35,12 @@ for (var i=2; i < tree.length; i++) { | ||
complete.fn = function(describeFn) { | ||
describeFn = describeFn || describe; | ||
complete.globalFn(); | ||
describeFn(complete.name, function() { | ||
complete.describes.forEach(function(parsedDescribe) { | ||
describeFn(parsedDescribe.name, parsedDescribe.fn); | ||
}); | ||
}); | ||
}; | ||
return complete; | ||
@@ -36,3 +51,3 @@ }, | ||
var node = tree[offset], | ||
describe = { | ||
parsedDescribe = { | ||
name: node[2], | ||
@@ -42,3 +57,6 @@ it: [] | ||
describe.beforeEach = parser.parseCodeBlocks(tree, offset); | ||
parsedDescribe.beforeEach = parser.parseCodeBlocks(tree, offset); | ||
parsedDescribe.beforeEachFn = function() { | ||
eval(parsedDescribe.beforeEach); | ||
}; | ||
@@ -54,7 +72,15 @@ while (true) { | ||
if (parser.validNode(child, 'header', IT_LEVEL)) { | ||
describe.it.push(parser.parseIt(tree, offset)); | ||
parsedDescribe.it.push(parser.parseIt(tree, offset)); | ||
} | ||
} | ||
return describe; | ||
parsedDescribe.fn = function(itFn) { | ||
itFn = itFn || it; | ||
beforeEach(parsedDescribe.beforeEachFn); | ||
parsedDescribe.it.forEach(function(parsedIt) { | ||
itFn(parsedIt.name, parsedIt.fn); | ||
}); | ||
}; | ||
return parsedDescribe; | ||
}, | ||
@@ -70,2 +96,6 @@ | ||
it.fn = function() { | ||
eval(it.code); | ||
}; | ||
return it; | ||
@@ -72,0 +102,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
91041
9
279
71
3