Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

literate-jasmine

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

literate-jasmine - npm Package Compare versions

Comparing version 0.0.27 to 0.1.0

spec/linter_spec.js

3

package.json
{
"name": "literate-jasmine",
"description": "write jasmine tests in markdown",
"version": "0.0.27",
"version": "0.1.0",
"bin": {

@@ -12,2 +12,3 @@ "literate-jasmine": "./bin/literate-jasmine"

"jasmine-node": "1.13.1",
"jshint": "2.4.3",
"lodash": "2.4.1",

@@ -14,0 +15,0 @@ "markdown": "0.5.0",

@@ -9,2 +9,4 @@ var assert = require('assert'),

sinon.spy(console, 'log');
sinon.stub(process, 'exit');
process.argv[2] = __dirname + '/markdown/reference_describe.md';

@@ -14,4 +16,5 @@ require('../bin/literate-jasmine');

setTimeout(function() {
assert(console.log.calledWith('ReferenceError: d is not defined'.red, 'thrown from', 'b'.red, 'in', './spec/markdown/reference_describe.md'.red + ':'));
assert(console.log.calledWith('c = 20 * d;'.red));
assert(console.log.calledWith('c = 20 * d;'.yellow + '\t' + "// ERROR: 'd' is not defined.".red));
assert(console.log.calledWith('Parsed code failed to pass JSHint. Please correct errors indicated above.'.red));
assert(process.exit.calledWith(1));

@@ -18,0 +21,0 @@ console.log('NOTE: Jasmine failure expected, watch for assertion failure!'.yellow);

@@ -9,2 +9,4 @@ var assert = require('assert'),

sinon.spy(console, 'log');
sinon.stub(process, 'exit');
process.argv[2] = __dirname + '/markdown/reference_it.md';

@@ -14,4 +16,5 @@ require('../bin/literate-jasmine');

setTimeout(function() {
assert(console.log.calledWith('ReferenceError: zz is not defined'.red, 'thrown from', 'c'.red, 'in', './spec/markdown/reference_it.md'.red + ':'));
assert(console.log.calledWith('c = 2 * zz;'.red));
assert(console.log.calledWith('c = 2 * zz;'.yellow + '\t' + "// ERROR: 'zz' is not defined.".red));
assert(console.log.calledWith('Parsed code failed to pass JSHint. Please correct errors indicated above.'.red));
assert(process.exit.calledWith(1));

@@ -18,0 +21,0 @@ console.log('NOTE: Jasmine failure expected, watch for assertion failure!'.yellow);

@@ -9,14 +9,11 @@ var assert = require('assert'),

sinon.spy(console, 'log');
try {
process.argv[2] = __dirname + '/markdown/reference_root.md';
require('../bin/literate-jasmine');
}
catch (e) {
// swallow for purpose of integration test -- for real failure, we are fine with
// throwing the exception!
}
sinon.stub(process, 'exit');
process.argv[2] = __dirname + '/markdown/reference_root.md';
require('../bin/literate-jasmine');
setTimeout(function() {
assert(console.log.calledWith('ReferenceError: xyz is not defined'.red, 'thrown from', 'a'.red, 'in', './spec/markdown/reference_root.md'.red + ':'));
assert(console.log.calledWith('var c = xyz;'.red));
assert(console.log.calledWith('var c = xyz;'.yellow + '\t' + "// ERROR: 'xyz' is not defined.".red));
assert(console.log.calledWith('Parsed code failed to pass JSHint. Please correct errors indicated above.'.red));
assert(process.exit.calledWith(1));

@@ -23,0 +20,0 @@ console.log('NOTE: Jasmine failure expected, watch for assertion failure!'.yellow);

@@ -8,5 +8,1 @@ # a

c = 20 * d;
### c
c = 200;

@@ -64,3 +64,5 @@ var Parser = require('../src/parser'),

var text,
tree;
tree,
parsedDescribe,
parsedRoot;

@@ -81,6 +83,15 @@ beforeEach(function() {

tree = markdown.parse(text);
parsedRoot = {
global: ''
};
parsedDescribe = {
parent: parsedRoot,
beforeEach: ''
};
});
it('parses out the name', function() {
var parsedIt = parser.parseSpec(tree, 1);
var parsedIt = parser.parseSpec(tree, 1, parsedDescribe);

@@ -91,3 +102,3 @@ expect(parsedIt.name).toBe('it 1');

it('parses out the code', function() {
var parsedIt = parser.parseSpec(tree, 1);
var parsedIt = parser.parseSpec(tree, 1, parsedDescribe);

@@ -99,3 +110,3 @@ expect(parsedIt.code).toBe('var x = 10;\nconsole.log("x", x);\nexpect(x).toBe(10);');

spyOn(console, 'log');
var parsedIt = parser.parseSpec(tree, 1);
var parsedIt = parser.parseSpec(tree, 1, parsedDescribe);

@@ -110,3 +121,4 @@ parsedIt.fn();

var text,
tree;
tree,
parsedRoot;

@@ -131,6 +143,15 @@ beforeEach(function() {

tree = markdown.parse(text);
parsedRoot = {
global: 'var someGlobal;'
};
parsedDescribe = {
parent: parsedRoot,
beforeEach: ''
};
});
it('parses the describe name', function() {
var parsedDescribe = parser.parseDescribe(tree, 1);
var parsedDescribe = parser.parseDescribe(tree, 1, parsedRoot);

@@ -141,3 +162,3 @@ expect(parsedDescribe.name).toBe('can set a variable to a number');

it('parsers out the it blocks', function() {
var parsedDescribe = parser.parseDescribe(tree, 1);
var parsedDescribe = parser.parseDescribe(tree, 1, parsedRoot);

@@ -148,3 +169,3 @@ expect(parsedDescribe.spec.length).toBe(1);

it('parses out any code blocks before the it as a beforeEach', function() {
var parsedDescribe = parser.parseDescribe(tree, 1);
var parsedDescribe = parser.parseDescribe(tree, 1, parsedRoot);

@@ -155,3 +176,3 @@ expect(parsedDescribe.beforeEach).toContain('someGlobal = 42;');

it('adds a function call to run the beforeEach', function() {
var parsedDescribe = parser.parseDescribe(tree, 1);
var parsedDescribe = parser.parseDescribe(tree, 1, parsedRoot);
someGlobal = 21;

@@ -166,3 +187,3 @@

var itSpy = jasmine.createSpy('it'),
parsedDescribe = parser.parseDescribe(tree, 1);
parsedDescribe = parser.parseDescribe(tree, 1, parsedRoot);

@@ -184,3 +205,2 @@ parsedDescribe.fn(itSpy);

' var someGlobal = 21;',
' someOtherRealGlobal = 500;',
'',

@@ -224,8 +244,5 @@ '## can set a variable to a number',

it('adds a function to call for global setup', function() {
someOtherRealGlobal = -5;
var result = parser.parse(text);
result.globalFn();
expect(someOtherRealGlobal).toBe(500);
expect(typeof result.globalFn).toBe('function');
});

@@ -232,0 +249,0 @@

require('jasmine-node');
var colors = require('colors'),
var _ = require('lodash'),
colors = require('colors'),
linter = require('./linter'),
markdown = require('markdown').markdown,

@@ -55,4 +57,5 @@ errorReporter = require('./error-reporter'),

complete = {
name: getName(root),
describes: []
isRoot: true,
describes: [],
name: getName(root)
};

@@ -70,3 +73,3 @@

if (validNode(node, 'header', DESCRIBE_LEVEL)) {
complete.describes.push(this.parseDescribe(tree, i));
complete.describes.push(this.parseDescribe(tree, i, complete));
}

@@ -88,4 +91,16 @@ }

this.run = function(name, code) {
var fileName = this.fileName;
this.run = function(name, code, codeBefore) {
var fileName = this.fileName,
codeToLint = [
codeBefore,
code
].join('\n\n');
if (!linter(codeToLint)) {
console.log();
console.log('Parsed code failed to pass JSHint. Please correct errors indicated above.'.red);
process.exit(1);
return _.noop;
}
if (isAsync(code)) {

@@ -102,6 +117,7 @@ return function(done) {

this.parseDescribe = function(tree, offset) {
this.parseDescribe = function(tree, offset, parent) {
var node = tree[offset],
parsedDescribe = {
name: getName(node),
parent: parent,
spec: []

@@ -111,3 +127,3 @@ };

parsedDescribe.beforeEach = this.parseCodeBlocks(tree, offset);
parsedDescribe.beforeEachFn = this.run(parsedDescribe.name, parsedDescribe.beforeEach);
parsedDescribe.beforeEachFn = this.run(parsedDescribe.name, parsedDescribe.beforeEach, parent.global);

@@ -123,3 +139,3 @@ while (true) {

if (validNode(child, 'header', SPEC_LEVEL)) {
parsedDescribe.spec.push(this.parseSpec(tree, offset));
parsedDescribe.spec.push(this.parseSpec(tree, offset, parsedDescribe));
}

@@ -139,10 +155,14 @@ }

this.parseSpec = function(tree, offset) {
this.parseSpec = function(tree, offset, parent) {
var node = tree[offset],
codeBefore,
spec = {
name: getName(node)
name: getName(node),
parent: parent
};
codeBefore = [parent.parent.global, parent.beforeEach].join('\n\n');
spec.code = this.parseCodeBlocks(tree, offset);
spec.fn = this.run(spec.name, spec.code);
spec.fn = this.run(spec.name, spec.code, codeBefore);

@@ -149,0 +169,0 @@ return spec;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc