Skip to content
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

Add tap support for unit tests #498

Merged
merged 1 commit into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ module.exports = function (grunt) {
nodeunit: {
all: ['test/*_tests.js']
},
tape: {
options: {
pretty: true,
output: 'console'
},
files: ['test/*_tests.js']
},
eslint: {
options: {
configFile: './.eslintrc'
Expand All @@ -31,11 +38,12 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-tape');

//travis CI task
grunt.registerTask('travis', ['nodeunit', 'eslint']);
grunt.registerTask('travis', ['nodeunit', 'tape', 'eslint']);

//to be run prior to releasing a version
grunt.registerTask('build', ['nodeunit', 'eslint', 'concat']);
grunt.registerTask('build', ['nodeunit', 'tape', 'eslint', 'concat']);

};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"grunt": "~1.0.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-nodeunit": "^1.0.0",
"grunt-eslint": "^18.0.0"
"grunt-eslint": "^18.0.0",
"grunt-tape": "^0.1.0",
"tap": "^7.1.2"
},
"keywords": [
"Pattern Lab",
Expand All @@ -44,7 +46,7 @@
],
"license": "MIT",
"scripts": {
"test": "grunt travis --verbose"
"test": "node_modules/grunt/bin/grunt travis --verbose"
},
"engines": {
"node": ">=4.0"
Expand Down
112 changes: 54 additions & 58 deletions test/annotation_exporter_tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

var eol = require('os').EOL;
var Pattern = require('../core/lib/object_factory').Pattern;
var tap = require('tap');

var extend = require('util')._extend;
var anPath = './test/files/';

Expand All @@ -22,59 +22,55 @@ function createFakePatternLab(anPath, customProps) {
var patternlab = createFakePatternLab(anPath);
var ae = require('../core/lib/annotation_exporter')(patternlab);

exports['annotaton_exporter'] = {

'converts old JS annotations into new format': function (test) {
//arrange
//act
var annotations = ae.gatherJS();

//assert
test.equals(annotations.length, 2);
test.equals(annotations[1].el, '.logo');
test.equals(annotations[1].title, 'Logo');
test.equals(annotations[1].comment, "The logo image is an SVG file, which ensures that the logo displays crisply even on high resolution displays. A PNG fallback is provided for browsers that don't support SVG images.</p><p>Further reading: <a href=\"http://bradfrostweb.com/blog/mobile/hi-res-optimization/\">Optimizing Web Experiences for High Resolution Screens</a></p>");

test.done();
},

'converts new markdown annotations into an array': function (test) {
//arrange
//act
var annotations = ae.gatherMD();

//assert
test.equals(annotations.length, 3);
test.equals(annotations[1].el, '.logo');
test.equals(annotations[1].title, 'Logo');
test.equals(annotations[1].comment.replace(/\r?\n|\r/gm, ""), '<p>The <em>logo image</em> is an SVG file.</p>');

test.done();
},

'merges both annotation methods into one array' : function (test) {
//arrange

//act
var annotations = ae.gather();

//assert
test.equals(annotations.length, 3);
test.equals(annotations[2].el, '#nav');
test.equals(annotations[2].title, 'Navigation');
test.equals(annotations[2].comment.replace(/\r?\n|\r/gm, ""), '<p>Navigation for adaptive web experiences can be tricky. Refer to <a href="https://bradfrost.github.io/this-is-responsive/patterns.html#navigation">these repsonsive patterns</a> when evaluating solutions.</p>');

test.done();

},

'when there are 0 annotation files' : function (test) {
var emptyAnPath = './test/files/empty/';
var patternlab2 = createFakePatternLab(emptyAnPath);
var ae2 = require('../core/lib/annotation_exporter')(patternlab2);

var annotations = ae2.gather();
test.equals(annotations.length, 0);
test.done();
}
};
tap.test('converts old JS annotations into new format', function (test) {
//arrange
//act
var annotations = ae.gatherJS();

//assert
test.equals(annotations.length, 2);
test.equals(annotations[1].el, '.logo');
test.equals(annotations[1].title, 'Logo');
test.equals(annotations[1].comment, "The logo image is an SVG file, which ensures that the logo displays crisply even on high resolution displays. A PNG fallback is provided for browsers that don't support SVG images.</p><p>Further reading: <a href=\"http://bradfrostweb.com/blog/mobile/hi-res-optimization/\">Optimizing Web Experiences for High Resolution Screens</a></p>");

test.end();
});

tap.test('converts new markdown annotations into an array', function (test) {
//arrange
//act
var annotations = ae.gatherMD();

//assert
test.equals(annotations.length, 3);
test.equals(annotations[1].el, '.logo');
test.equals(annotations[1].title, 'Logo');
test.equals(annotations[1].comment.replace(/\r?\n|\r/gm, ""), '<p>The <em>logo image</em> is an SVG file.</p>');

test.end();
});

tap.test('merges both annotation methods into one array', function (test) {
//arrange

//act
var annotations = ae.gather();

//assert
test.equals(annotations.length, 3);
test.equals(annotations[2].el, '#nav');
test.equals(annotations[2].title, 'Navigation');
test.equals(annotations[2].comment.replace(/\r?\n|\r/gm, ""), '<p>Navigation for adaptive web experiences can be tricky. Refer to <a href="https://bradfrost.github.io/this-is-responsive/patterns.html#navigation">these repsonsive patterns</a> when evaluating solutions.</p>');

test.end();
});

tap.test('when there are 0 annotation files', function (test) {
var emptyAnPath = './test/files/empty/';
var patternlab2 = createFakePatternLab(emptyAnPath);
var ae2 = require('../core/lib/annotation_exporter')(patternlab2);

var annotations = ae2.gather();
test.equals(annotations.length, 0);
test.end();
});