mirror of
https://github.com/wassname/template.git
synced 2026-06-27 19:01:31 +08:00
Add tests; test transforms usesTemplateV2
This commit is contained in:
@@ -0,0 +1 @@
|
||||
-r jsdom-global/register
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="https://distill.pub/template.v1.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
</body>
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="https://distill.pub/template.v2.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
</body>
|
||||
@@ -1,46 +1,50 @@
|
||||
/* global it, should, describe */
|
||||
|
||||
// Test format: https://mochajs.org/#bdd
|
||||
// Assertion format: http://chaijs.com/api/bdd/
|
||||
|
||||
let expect = require('chai').expect,
|
||||
jsdom = require("jsdom"),
|
||||
distill = require("../dist/template.js");
|
||||
let expect = require('chai').expect;
|
||||
let jsdom = require('jsdom');
|
||||
// let distill = require('../dist/template.v1.js');
|
||||
|
||||
describe("Distill", function() {
|
||||
describe("render", function() {
|
||||
it("Should have a render function.", function() {
|
||||
describe.skip('Distill v1', function() {
|
||||
|
||||
describe('render', function() {
|
||||
it('Should have a render function.', function() {
|
||||
expect(distill.render).to.be.an.instanceof(Function);
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
// html
|
||||
//
|
||||
describe("html", function() {
|
||||
it("Should have a html function.", function() {
|
||||
describe.skip('html', function() {
|
||||
it('Should have a html function.', function() {
|
||||
expect(distill.html).to.be.an.instanceof(Function);
|
||||
});
|
||||
it("Should add a language attribute to html element, if not present.", function() {
|
||||
var doc = jsdom.jsdom("");
|
||||
it('Should add a language attribute to html element, if not present.', function() {
|
||||
var doc = jsdom.jsdom('');
|
||||
let before = jsdom.serializeDocument(doc);
|
||||
distill.html(doc, {});
|
||||
let after = jsdom.serializeDocument(doc);
|
||||
expect(after).to.match(new RegExp('<html lang="en">'));
|
||||
});
|
||||
it("Should not add a language attribute to html element, if already present.", function() {
|
||||
it('Should not add a language attribute to html element, if already present.', function() {
|
||||
var doc = jsdom.jsdom('<html lang="ab">');
|
||||
let before = jsdom.serializeDocument(doc);
|
||||
distill.html(doc, {});
|
||||
let after = jsdom.serializeDocument(doc);
|
||||
expect(after).to.not.match(new RegExp('lang="en"'));
|
||||
});
|
||||
it("Should add a meta charset tag, if not present.", function() {
|
||||
var doc = jsdom.jsdom("");
|
||||
it('Should add a meta charset tag, if not present.', function() {
|
||||
var doc = jsdom.jsdom('');
|
||||
let before = jsdom.serializeDocument(doc);
|
||||
distill.html(doc, {});
|
||||
let after = jsdom.serializeDocument(doc);
|
||||
expect(after).to.match(new RegExp('<meta charset="utf-8">'));
|
||||
});
|
||||
it("Should add a meta viewport tag, if not present.", function() {
|
||||
var doc = jsdom.jsdom("");
|
||||
it('Should add a meta viewport tag, if not present.', function() {
|
||||
var doc = jsdom.jsdom('');
|
||||
let before = jsdom.serializeDocument(doc);
|
||||
distill.html(doc, {});
|
||||
let after = jsdom.serializeDocument(doc);
|
||||
@@ -51,8 +55,8 @@ describe("Distill", function() {
|
||||
//
|
||||
// styles
|
||||
//
|
||||
describe("styles", function() {
|
||||
it("Should have a styles function.", function() {
|
||||
describe.skip('styles', function() {
|
||||
it('Should have a styles function.', function() {
|
||||
expect(distill.styles).to.be.an.instanceof(Function);
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
/* global it, should, describe, before, beforeEach, after, afterEach */
|
||||
|
||||
const jsdom = require("jsdom");
|
||||
const { JSDOM } = jsdom;
|
||||
|
||||
const expect = require('chai').expect;
|
||||
const distill = require('../dist/transforms.v2.js');
|
||||
|
||||
describe('Distill V2 (transforms)', function() {
|
||||
|
||||
it('should export usesTemplateV2()', function() {
|
||||
expect(distill.usesTemplateV2).to.be.a('function');
|
||||
});
|
||||
|
||||
describe('#usesTemplateV2()', function() {
|
||||
|
||||
it('should detect v1', function() {
|
||||
const frag = JSDOM.fragment('<script src="https://distill.pub/template.v1.js"></script>');
|
||||
expect(distill.usesTemplateV2(frag)).to.be.false;
|
||||
});
|
||||
|
||||
it('should detect v2', function() {
|
||||
const frag = JSDOM.fragment('<script src="https://distill.pub/template.v2.js"></script>');
|
||||
expect(distill.usesTemplateV2(frag)).to.be.true;
|
||||
});
|
||||
|
||||
it('should error on unknown distill script', function() {
|
||||
const frag = JSDOM.fragment('<script src="https://distill.pub/unknown.v2.js"></script>');
|
||||
expect(()=> distill.usesTemplateV2(frag)).to.throw('unknown');
|
||||
});
|
||||
|
||||
it('should error on no distill script', function() {
|
||||
const frag = JSDOM.fragment('<script src="https://code.jquery.com/jquery-3.2.1.js"></script>');
|
||||
expect(()=> distill.usesTemplateV2(frag)).to.throw('at all');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('should export render()', function() {
|
||||
expect(distill.render).to.be.a('function');
|
||||
});
|
||||
|
||||
describe('#render()', function() {
|
||||
|
||||
it('should extract metadata');
|
||||
it('should run transforms');
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('should export #distillify()', function() {
|
||||
expect(distill.distillify).to.be.a('function');
|
||||
});
|
||||
|
||||
describe('#distillify()', function() {
|
||||
|
||||
it('should ensure existence of header');
|
||||
it('should ensure existence of footer');
|
||||
it('should ensure existence of distill appendix');
|
||||
|
||||
});
|
||||
|
||||
}); // describe 'Render'
|
||||
Reference in New Issue
Block a user