mirror of
https://github.com/marko-js/marko.git
synced 2026-02-01 16:07:13 +00:00
Reorganized tests
This commit is contained in:
parent
a356099a4a
commit
5df81440e5
@ -9,19 +9,17 @@ var autotest = require('./autotest');
|
||||
var fs = require('fs');
|
||||
|
||||
describe('compiler/util/adjustIndent', function() {
|
||||
var autoTestDir = path.join(__dirname, 'fixtures/adjustIndent/autotest');
|
||||
var autoTestDir = path.join(__dirname, 'autotests/adjustIndent');
|
||||
|
||||
autotest.scanDir(
|
||||
autoTestDir,
|
||||
function run(dir) {
|
||||
function run(dir, helpers, done) {
|
||||
var inputPath = path.join(dir, 'input.txt');
|
||||
var testSettings = require(path.join(dir, 'test.js'));
|
||||
var input = fs.readFileSync(inputPath, { encoding: 'utf8' });
|
||||
var newIndentation = testSettings.newIndentation;
|
||||
var output = adjustIndent(input, newIndentation);
|
||||
return output;
|
||||
},
|
||||
{
|
||||
compareExtension: '.txt'
|
||||
helpers.compare(output, '.txt');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -1,455 +1,22 @@
|
||||
'use strict';
|
||||
require('./patch-module');
|
||||
require('marko/node-require').install();
|
||||
|
||||
var chai = require('chai');
|
||||
chai.config.includeStack = true;
|
||||
|
||||
var expect = require('chai').expect;
|
||||
var nodePath = require('path');
|
||||
require('../compiler');
|
||||
var autotest = require('./autotest');
|
||||
var marko = require('../');
|
||||
var through = require('through');
|
||||
var fs = require('fs');
|
||||
|
||||
require('../node-require').install();
|
||||
var markoCompiler = require('../compiler');
|
||||
|
||||
describe('api' , function() {
|
||||
var autoTestDir = nodePath.join(__dirname, 'autotests/api');
|
||||
|
||||
before(function() {
|
||||
require('../compiler').defaultOptions.checkUpToDate = false;
|
||||
autotest.scanDir(autoTestDir, function run(dir, helpers, done) {
|
||||
var test = require(nodePath.join(dir, 'test.js'));
|
||||
test.check(marko, markoCompiler, expect, done);
|
||||
});
|
||||
|
||||
beforeEach(function(done) {
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should allow a template to be rendered using a callback', function(done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
function(err, output) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow a template to be rendered to a writer wrapping a string builder', function(done) {
|
||||
var out = marko.createWriter();
|
||||
out
|
||||
.on('finish', function() {
|
||||
expect(out.getOutput()).to.equal('Hello John!');
|
||||
done();
|
||||
})
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
out);
|
||||
|
||||
out.end();
|
||||
});
|
||||
|
||||
it('should allow a template to be rendered to a writer wrapping a stream', function(done) {
|
||||
var output = '';
|
||||
|
||||
var stream = through(function write(data) {
|
||||
output += data;
|
||||
});
|
||||
|
||||
var out = marko.createWriter(stream);
|
||||
out
|
||||
.on('end', function() {
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
})
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
out).end();
|
||||
});
|
||||
|
||||
it('should allow a template to be rendered to a stream', function(done) {
|
||||
var output = '';
|
||||
var outStream = through(function write(data) {
|
||||
output += data;
|
||||
});
|
||||
|
||||
outStream.on('end', function() {
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
var template = require(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
template.stream(
|
||||
{
|
||||
name: 'John'
|
||||
})
|
||||
.pipe(outStream)
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/// TEMPLATE LOADING:
|
||||
|
||||
it('should allow a template to be loaded and rendered using a callback', function(done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
function(err, output) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow a template to be loaded and rendered to a writer wrapping a string builder', function(done) {
|
||||
var out = marko.createWriter();
|
||||
out
|
||||
.on('finish', function() {
|
||||
expect(out.getOutput()).to.equal('Hello John!');
|
||||
done();
|
||||
})
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
out);
|
||||
|
||||
out.end();
|
||||
});
|
||||
|
||||
it('should allow a template to be loaded and rendered to a writer wrapping a stream', function(done) {
|
||||
|
||||
var output = '';
|
||||
|
||||
var stream = through(function write(data) {
|
||||
output += data;
|
||||
});
|
||||
|
||||
var out = marko.createWriter(stream)
|
||||
.on('end', function() {
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
})
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
out).end();
|
||||
});
|
||||
|
||||
it('should allow a template to be loaded and rendered to a stream', function(done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
|
||||
var output = '';
|
||||
var outStream = through(function write(data) {
|
||||
output += data;
|
||||
});
|
||||
|
||||
outStream.on('end', function() {
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
template.stream({
|
||||
name: 'John'
|
||||
})
|
||||
.pipe(outStream)
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow a template to be rendered to a string synchronously using renderSync', function() {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
var output = template.renderSync({ name: 'John' });
|
||||
expect(output).to.equal('Hello John!');
|
||||
});
|
||||
|
||||
it('should allow a template to be rendered synchronously using global attributes', function() {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello-global.marko'));
|
||||
var data = {
|
||||
name: 'John',
|
||||
$global: {
|
||||
greeting: 'Greetings'
|
||||
}
|
||||
};
|
||||
var output = template.renderSync(data);
|
||||
expect(output).to.equal('Greetings John!');
|
||||
});
|
||||
|
||||
it('should allow a template to be rendered asynchronously using global attributes', function(done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello-global.marko'));
|
||||
var data = {
|
||||
name: 'John',
|
||||
$global: {
|
||||
greeting: 'Greetings'
|
||||
}
|
||||
};
|
||||
template.render(data, function(error, output) {
|
||||
expect(output).to.equal('Greetings John!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error if beginAsync is used with renderSync', function() {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello-async.marko'));
|
||||
var output;
|
||||
var e;
|
||||
|
||||
try {
|
||||
output = template.renderSync({
|
||||
nameDataProvider: function(arg, callback) {
|
||||
setTimeout(function() {
|
||||
callback(null, 'John');
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
}
|
||||
|
||||
expect(output).to.equal(undefined);
|
||||
expect(e).to.not.equal(undefined);
|
||||
});
|
||||
|
||||
it('should throw errors correctly with renderSync', function() {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello-error.marko'));
|
||||
var output;
|
||||
var e;
|
||||
|
||||
try {
|
||||
output = template.renderSync();
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
}
|
||||
|
||||
expect(output).to.equal(undefined);
|
||||
expect(e).to.not.equal(undefined);
|
||||
});
|
||||
|
||||
it('should handle no context passed to renderSync', function() {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello-empty.marko'));
|
||||
var output = template.renderSync();
|
||||
|
||||
expect(output).to.equal('Hello!');
|
||||
});
|
||||
|
||||
it('should allow a template to be loaded from a compiled JS module', function(done) {
|
||||
// Load the JS file to ensure the hello.marko.js file is created
|
||||
marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));
|
||||
|
||||
var templateModule = require(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko.js'));
|
||||
|
||||
var template = marko.load(templateModule);
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
function(err, output) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow a template to be required', function(done) {
|
||||
var templatePath = nodePath.join(__dirname, 'fixtures/api-tests/hello.marko');
|
||||
var template = require(templatePath);
|
||||
template.render(
|
||||
{
|
||||
name: 'John'
|
||||
},
|
||||
function(err, output) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow global data with callback-style render', function(done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/global-data.marko'));
|
||||
template.render({
|
||||
$global: {
|
||||
foo: 'bar'
|
||||
}
|
||||
},
|
||||
function(err, output) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(output).to.equal('bar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow global data with render to writable stream', function(done) {
|
||||
var output = '';
|
||||
|
||||
var stream = through(function write(data) {
|
||||
output += data;
|
||||
});
|
||||
|
||||
stream.on('end', function() {
|
||||
expect(output).to.equal('bar');
|
||||
done();
|
||||
})
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/global-data.marko'));
|
||||
template.render(
|
||||
{
|
||||
$global: {
|
||||
foo: 'bar'
|
||||
}
|
||||
},
|
||||
stream);
|
||||
});
|
||||
|
||||
it('should write compiled templates to disk by default when using the Node.js require extension', function() {
|
||||
var compiledPath;
|
||||
|
||||
try {
|
||||
var templatePath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko');
|
||||
compiledPath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko.js');
|
||||
var template = require(templatePath);
|
||||
delete require.cache[templatePath];
|
||||
expect(fs.existsSync(compiledPath)).to.equal(true);
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
} finally {
|
||||
fs.unlinkSync(compiledPath);
|
||||
}
|
||||
});
|
||||
|
||||
it('should write compiled templates to disk by default when using load', function() {
|
||||
|
||||
var compiledPath;
|
||||
|
||||
try {
|
||||
var templatePath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko');
|
||||
compiledPath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko.js');
|
||||
var template = marko.load(templatePath);
|
||||
expect(fs.existsSync(compiledPath)).to.equal(true);
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
} finally {
|
||||
fs.unlinkSync(compiledPath);
|
||||
}
|
||||
});
|
||||
|
||||
it('should allow compiled templates to not be written to disk when using the Node.js require extension', function() {
|
||||
require('../compiler').defaultOptions.writeToDisk = false;
|
||||
try {
|
||||
var templatePath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko');
|
||||
var compiledPath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko.js');
|
||||
var template = require(templatePath);
|
||||
expect(fs.existsSync(compiledPath)).to.equal(false);
|
||||
expect(template.render).to.be.a('function');
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
} finally {
|
||||
require('../compiler').defaultOptions.writeToDisk = true;
|
||||
}
|
||||
});
|
||||
|
||||
it('should allow compiled templates to not be written to disk when using load', function() {
|
||||
require('../compiler').defaultOptions.writeToDisk = false;
|
||||
try {
|
||||
var templatePath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko');
|
||||
var compiledPath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko.js');
|
||||
var template = marko.load(templatePath);
|
||||
expect(fs.existsSync(compiledPath)).to.equal(false);
|
||||
expect(template.render).to.be.a('function');
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
} finally {
|
||||
require('../compiler').defaultOptions.writeToDisk = true;
|
||||
}
|
||||
});
|
||||
|
||||
it('should allow a template to be loaded from source', function() {
|
||||
var template;
|
||||
var templatePath;
|
||||
|
||||
// Make sure calling load with templatePath:String, templateSrc:String arguments works
|
||||
templatePath = nodePath.join(__dirname, 'dummy.marko');
|
||||
template = marko.load(templatePath, '- Hello $!{data.name}!');
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
|
||||
// Make sure calling load with templatePath:String, templateSrc:String, options:Object arguments works
|
||||
templatePath = nodePath.join(__dirname, 'dummy.marko');
|
||||
template = marko.load(templatePath, '- Hello $!{data.name}!', {});
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
|
||||
// Make sure calling load with templatePath:String, options:Object arguments works
|
||||
delete require('../compiler').defaultOptions.writeToDisk;
|
||||
|
||||
templatePath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko');
|
||||
var compiledPath = nodePath.join(__dirname, 'fixtures/api-tests/write-to-disk.marko.js');
|
||||
|
||||
try {
|
||||
fs.unlinkSync(compiledPath);
|
||||
} catch(e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
template = marko.load(templatePath, {writeToDisk: false});
|
||||
expect(fs.existsSync(compiledPath)).to.equal(false);
|
||||
expect(template.render).to.be.a('function');
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
});
|
||||
|
||||
it('should allow configure()', function() {
|
||||
var compiler = require('marko/compiler');
|
||||
compiler.configure(); // Use defaults
|
||||
expect(compiler.config.writeToDisk).to.equal(true);
|
||||
expect(compiler.config.preserveWhitespace).to.equal(false);
|
||||
|
||||
compiler.configure({
|
||||
preserveWhitespace: true
|
||||
});
|
||||
expect(compiler.config.writeToDisk).to.equal(true);
|
||||
expect(compiler.config.preserveWhitespace).to.equal(true);
|
||||
|
||||
compiler.configure(); // Use defaults
|
||||
expect(compiler.config.writeToDisk).to.equal(true);
|
||||
expect(compiler.config.preserveWhitespace).to.equal(false);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -11,11 +11,11 @@ var fs = require('fs');
|
||||
require('../node-require').install();
|
||||
|
||||
describe('render', function() {
|
||||
var autoTestDir = path.join(__dirname, 'fixtures/async-render/autotest');
|
||||
var autoTestDir = path.join(__dirname, 'autotests/async-render');
|
||||
|
||||
autotest.scanDir(
|
||||
autoTestDir,
|
||||
function run(dir, callback) {
|
||||
function run(dir, helpers, done) {
|
||||
var templatePath = path.join(dir, 'template.marko');
|
||||
var mainPath = path.join(dir, 'test.js');
|
||||
|
||||
@ -36,23 +36,23 @@ describe('render', function() {
|
||||
}
|
||||
|
||||
main.checkError(e);
|
||||
return callback(null, '$PASS$');
|
||||
return done();
|
||||
} else {
|
||||
var template = marko.load(templatePath, loadOptions);
|
||||
var templateData = main.templateData || {};
|
||||
template.render(templateData, function(err, html) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (main.checkHtml) {
|
||||
main.checkHtml(html);
|
||||
return callback(null, '$PASS$');
|
||||
done();
|
||||
} else {
|
||||
callback(err, html);
|
||||
helpers.compare(html, '.html');
|
||||
done();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
compareExtension: '.html'
|
||||
});
|
||||
});
|
||||
155
test/autotest.js
155
test/autotest.js
@ -16,128 +16,73 @@ if (enabledTestNames && enabledTestNames.length > 1) {
|
||||
});
|
||||
}
|
||||
|
||||
function autoTest(name, dir, run, options, done) {
|
||||
var compareExtension = (options && options.compareExtension) || '.js';
|
||||
var isJSON = compareExtension === '.json';
|
||||
var fs = require('fs');
|
||||
var enabledTest = process.env.TEST;
|
||||
var path = require('path');
|
||||
var assert = require('assert');
|
||||
|
||||
var actualPath = path.join(dir, 'actual' + compareExtension);
|
||||
var expectedPath = path.join(dir, 'expected' + compareExtension);
|
||||
|
||||
function verify(actual) {
|
||||
if (actual === '$PASS$') {
|
||||
return;
|
||||
}
|
||||
function compareHelper(dir, actual, suffix) {
|
||||
var actualPath = path.join(dir, 'actual' + suffix);
|
||||
var expectedPath = path.join(dir, 'expected' + suffix);
|
||||
|
||||
var actualJSON = isJSON ? JSON.stringify(actual, null, 2) : null;
|
||||
var isObject = typeof actual === 'string' ? false : true;
|
||||
var actualString = isObject ? JSON.stringify(actual, null, 4) : actual;
|
||||
fs.writeFileSync(actualPath, actualString, { encoding: 'utf8' });
|
||||
|
||||
fs.writeFileSync(
|
||||
actualPath,
|
||||
isJSON ? actualJSON : actual,
|
||||
{encoding: 'utf8'});
|
||||
|
||||
var expected;
|
||||
|
||||
try {
|
||||
expected = fs.readFileSync(expectedPath, { encoding: 'utf8' });
|
||||
} catch(e) {
|
||||
expected = isJSON ? '"TBD"' : 'TBD';
|
||||
fs.writeFileSync(expectedPath, expected, {encoding: 'utf8'});
|
||||
}
|
||||
|
||||
var expectedJSON;
|
||||
|
||||
if (isJSON) {
|
||||
expectedJSON = expected;
|
||||
expected = JSON.parse(expectedJSON);
|
||||
}
|
||||
|
||||
assert.deepEqual(
|
||||
(isJSON ? JSON.parse(actualJSON) : actual),
|
||||
expected,
|
||||
'Unexpected output for "' + name + '":\nEXPECTED (' + expectedPath + '):\n---------\n' +
|
||||
(isJSON ? expectedJSON : expected) +
|
||||
'\n---------\nACTUAL (' + actualPath + '):\n---------\n' +
|
||||
(isJSON ? actualJSON : actual) +
|
||||
'\n---------');
|
||||
}
|
||||
var expectedString;
|
||||
|
||||
try {
|
||||
fs.unlinkSync(actualPath);
|
||||
} catch(e) {}
|
||||
|
||||
if (done) {
|
||||
// Async test
|
||||
run(dir, function(err, actual) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
verify(actual);
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
let actual = run(dir);
|
||||
verify(actual);
|
||||
expectedString = fs.readFileSync(expectedPath, { encoding: 'utf8' });
|
||||
} catch(e) {
|
||||
expectedString = isObject ? '"TBD"' : 'TBD';
|
||||
fs.writeFileSync(expectedPath, expectedString, {encoding: 'utf8'});
|
||||
}
|
||||
|
||||
if (isObject) {
|
||||
actual = JSON.parse(actualString);
|
||||
}
|
||||
|
||||
var expected = isObject ? JSON.parse(expectedString) : expectedString;
|
||||
assert.deepEqual(actual, expected);
|
||||
}
|
||||
|
||||
function autoTest(name, dir, run, options, done) {
|
||||
options = options || {};
|
||||
|
||||
var helpers = {
|
||||
compare(actual, suffix) {
|
||||
compareHelper(dir, actual, suffix);
|
||||
}
|
||||
};
|
||||
|
||||
run(dir, helpers, done);
|
||||
}
|
||||
|
||||
exports.scanDir = function(autoTestDir, run, options) {
|
||||
describe('autotest', function() {
|
||||
var files;
|
||||
try {
|
||||
files = fs.readdirSync(autoTestDir);
|
||||
} catch(e) {
|
||||
console.warn('autotest directory does not exist: ' + autoTestDir);
|
||||
}
|
||||
fs.readdirSync(autoTestDir)
|
||||
.forEach(function(name) {
|
||||
if (name.charAt(0) === '.') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (files) {
|
||||
files.forEach(function(name) {
|
||||
if (name.charAt(0) === '.') {
|
||||
return;
|
||||
}
|
||||
if (enabledTests && !enabledTests[name]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabledTests && !enabledTests[name]) {
|
||||
return;
|
||||
}
|
||||
|
||||
var itFunc = it;
|
||||
|
||||
if (enabledTest && name === enabledTest) {
|
||||
itFunc = it.only;
|
||||
}
|
||||
|
||||
var dir = path.join(autoTestDir, name);
|
||||
|
||||
if (run.length === 2) {
|
||||
itFunc(`[${name}] `, function(done) {
|
||||
autoTest(name, dir, run, options, done);
|
||||
});
|
||||
} else {
|
||||
itFunc(`[${name}] `, function() {
|
||||
autoTest(name, dir, run, options);
|
||||
});
|
||||
}
|
||||
var itFunc = it;
|
||||
|
||||
if (enabledTest && name === enabledTest) {
|
||||
itFunc = it.only;
|
||||
}
|
||||
|
||||
var dir = path.join(autoTestDir, name);
|
||||
|
||||
itFunc(`[${name}] `, function(done) {
|
||||
autoTest(name, dir, run, options, done);
|
||||
});
|
||||
}
|
||||
|
||||
var pendingFiles;
|
||||
try {
|
||||
pendingFiles = fs.readdirSync(autoTestDir + '-pending');
|
||||
} catch(e) {}
|
||||
|
||||
if (pendingFiles) {
|
||||
pendingFiles.forEach(function(name) {
|
||||
if (name.charAt(0) === '.') {
|
||||
return;
|
||||
}
|
||||
|
||||
xit(`[${name}] `, function() {
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
17
test/autotests/api-compiler/configure/test.js
Normal file
17
test/autotests/api-compiler/configure/test.js
Normal file
@ -0,0 +1,17 @@
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var compiler = require('marko/compiler');
|
||||
compiler.configure(); // Use defaults
|
||||
expect(compiler.config.writeToDisk).to.equal(true);
|
||||
expect(compiler.config.preserveWhitespace).to.equal(false);
|
||||
|
||||
compiler.configure({
|
||||
preserveWhitespace: true
|
||||
});
|
||||
expect(compiler.config.writeToDisk).to.equal(true);
|
||||
expect(compiler.config.preserveWhitespace).to.equal(true);
|
||||
|
||||
compiler.configure(); // Use defaults
|
||||
expect(compiler.config.writeToDisk).to.equal(true);
|
||||
expect(compiler.config.preserveWhitespace).to.equal(false);
|
||||
done();
|
||||
};
|
||||
16
test/autotests/api/compiler-configure/test.js
Normal file
16
test/autotests/api/compiler-configure/test.js
Normal file
@ -0,0 +1,16 @@
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
markoCompiler.configure(); // Use defaults
|
||||
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
||||
expect(markoCompiler.config.preserveWhitespace).to.equal(false);
|
||||
|
||||
markoCompiler.configure({
|
||||
preserveWhitespace: true
|
||||
});
|
||||
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
||||
expect(markoCompiler.config.preserveWhitespace).to.equal(true);
|
||||
|
||||
markoCompiler.configure(); // Use defaults
|
||||
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
||||
expect(markoCompiler.config.preserveWhitespace).to.equal(false);
|
||||
done();
|
||||
};
|
||||
@ -1,3 +1,3 @@
|
||||
<async-fragment data-provider=data.nameDataProvider var="name">
|
||||
Hello ${name}!
|
||||
</async-fragment>
|
||||
</async-fragment>
|
||||
23
test/autotests/api/error-renderSync-beginAsync/test.js
Normal file
23
test/autotests/api/error-renderSync-beginAsync/test.js
Normal file
@ -0,0 +1,23 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
var output;
|
||||
var e;
|
||||
|
||||
try {
|
||||
output = template.renderSync({
|
||||
nameDataProvider: function(arg, callback) {
|
||||
setTimeout(function() {
|
||||
callback(null, 'John');
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
}
|
||||
|
||||
expect(output).to.equal(undefined);
|
||||
expect(e).to.not.equal(undefined);
|
||||
done();
|
||||
};
|
||||
17
test/autotests/api/error-renderSync/test.js
Normal file
17
test/autotests/api/error-renderSync/test.js
Normal file
@ -0,0 +1,17 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
var output;
|
||||
var e;
|
||||
|
||||
try {
|
||||
output = template.renderSync();
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
}
|
||||
|
||||
expect(output).to.equal(undefined);
|
||||
expect(e).to.not.equal(undefined);
|
||||
done();
|
||||
};
|
||||
1
test/autotests/api/load-render-callback/template.marko
Normal file
1
test/autotests/api/load-render-callback/template.marko
Normal file
@ -0,0 +1 @@
|
||||
- Hello ${data.name}!
|
||||
16
test/autotests/api/load-render-callback/test.js
Normal file
16
test/autotests/api/load-render-callback/test.js
Normal file
@ -0,0 +1,16 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
function(err, output) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
};
|
||||
1
test/autotests/api/load-source/template.marko
Normal file
1
test/autotests/api/load-source/template.marko
Normal file
@ -0,0 +1 @@
|
||||
- Hello ${data.name}!
|
||||
35
test/autotests/api/load-source/test.js
Normal file
35
test/autotests/api/load-source/test.js
Normal file
@ -0,0 +1,35 @@
|
||||
var nodePath = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var template;
|
||||
var templatePath;
|
||||
|
||||
// Make sure calling load with templatePath:String, templateSrc:String arguments works
|
||||
templatePath = nodePath.join(__dirname, 'dummy.marko');
|
||||
template = marko.load(templatePath, '- Hello $!{data.name}!');
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
|
||||
// Make sure calling load with templatePath:String, templateSrc:String, options:Object arguments works
|
||||
templatePath = nodePath.join(__dirname, 'dummy.marko');
|
||||
template = marko.load(templatePath, '- Hello $!{data.name}!', {});
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
|
||||
// Make sure calling load with templatePath:String, options:Object arguments works
|
||||
delete markoCompiler.defaultOptions.writeToDisk;
|
||||
|
||||
templatePath = nodePath.join(__dirname, 'template.marko');
|
||||
var compiledPath = nodePath.join(__dirname, 'template.marko.js');
|
||||
|
||||
try {
|
||||
fs.unlinkSync(compiledPath);
|
||||
} catch(e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
template = marko.load(templatePath, {writeToDisk: false});
|
||||
expect(fs.existsSync(compiledPath)).to.equal(false);
|
||||
expect(template.render).to.be.a('function');
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
done();
|
||||
};
|
||||
@ -0,0 +1 @@
|
||||
- Hello ${data.name}!
|
||||
27
test/autotests/api/load-writer-wrapping-stream/test.js
Normal file
27
test/autotests/api/load-writer-wrapping-stream/test.js
Normal file
@ -0,0 +1,27 @@
|
||||
var nodePath = require('path');
|
||||
var through = require('through');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var output = '';
|
||||
|
||||
var stream = through(function write(data) {
|
||||
output += data;
|
||||
});
|
||||
|
||||
var out = marko.createWriter(stream);
|
||||
out
|
||||
.on('end', function() {
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
})
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
out).end();
|
||||
};
|
||||
@ -0,0 +1,21 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var out = marko.createWriter();
|
||||
out
|
||||
.on('finish', function() {
|
||||
expect(out.getOutput()).to.equal('Hello John!');
|
||||
done();
|
||||
})
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
out);
|
||||
|
||||
out.end();
|
||||
};
|
||||
1
test/autotests/api/no-write-to-disk-load/template.marko
Normal file
1
test/autotests/api/no-write-to-disk-load/template.marko
Normal file
@ -0,0 +1 @@
|
||||
- Hello ${data.name}!
|
||||
18
test/autotests/api/no-write-to-disk-load/test.js
Normal file
18
test/autotests/api/no-write-to-disk-load/test.js
Normal file
@ -0,0 +1,18 @@
|
||||
var nodePath = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
markoCompiler.defaultOptions.writeToDisk = false;
|
||||
try {
|
||||
var templatePath = nodePath.join(__dirname, 'template.marko');
|
||||
var compiledPath = nodePath.join(__dirname, 'template.marko.js');
|
||||
var template = marko.load(templatePath);
|
||||
expect(fs.existsSync(compiledPath)).to.equal(false);
|
||||
expect(template.render).to.be.a('function');
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
} finally {
|
||||
markoCompiler.defaultOptions.writeToDisk = true;
|
||||
}
|
||||
|
||||
done();
|
||||
};
|
||||
@ -0,0 +1 @@
|
||||
- Hello ${data.name}!
|
||||
18
test/autotests/api/no-write-to-disk-require/test.js
Normal file
18
test/autotests/api/no-write-to-disk-require/test.js
Normal file
@ -0,0 +1,18 @@
|
||||
var nodePath = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
markoCompiler.defaultOptions.writeToDisk = false;
|
||||
try {
|
||||
var templatePath = nodePath.join(__dirname, 'template.marko');
|
||||
var compiledPath = nodePath.join(__dirname, 'template.marko.js');
|
||||
var template = require(templatePath);
|
||||
expect(fs.existsSync(compiledPath)).to.equal(false);
|
||||
expect(template.render).to.be.a('function');
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
} finally {
|
||||
markoCompiler.defaultOptions.writeToDisk = true;
|
||||
}
|
||||
|
||||
done();
|
||||
};
|
||||
15
test/autotests/api/render-callback-global-data/test.js
Normal file
15
test/autotests/api/render-callback-global-data/test.js
Normal file
@ -0,0 +1,15 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
var data = {
|
||||
name: 'John',
|
||||
$global: {
|
||||
greeting: 'Greetings'
|
||||
}
|
||||
};
|
||||
template.render(data, function(error, output) {
|
||||
expect(output).to.equal('Greetings John!');
|
||||
done();
|
||||
});
|
||||
};
|
||||
@ -0,0 +1,27 @@
|
||||
var nodePath = require('path');
|
||||
var through = require('through');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var output = '';
|
||||
|
||||
var stream = through(function write(data) {
|
||||
output += data;
|
||||
});
|
||||
|
||||
stream.on('end', function() {
|
||||
expect(output).to.equal('bar');
|
||||
done();
|
||||
})
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
template.render(
|
||||
{
|
||||
$global: {
|
||||
foo: 'bar'
|
||||
}
|
||||
},
|
||||
stream);
|
||||
};
|
||||
1
test/autotests/api/renderSync-global-data/template.marko
Normal file
1
test/autotests/api/renderSync-global-data/template.marko
Normal file
@ -0,0 +1 @@
|
||||
- ${out.global.greeting} ${data.name}!
|
||||
14
test/autotests/api/renderSync-global-data/test.js
Normal file
14
test/autotests/api/renderSync-global-data/test.js
Normal file
@ -0,0 +1,14 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
var data = {
|
||||
name: 'John',
|
||||
$global: {
|
||||
greeting: 'Greetings'
|
||||
}
|
||||
};
|
||||
var output = template.renderSync(data);
|
||||
expect(output).to.equal('Greetings John!');
|
||||
done();
|
||||
};
|
||||
1
test/autotests/api/renderSync-no-data/template.marko
Normal file
1
test/autotests/api/renderSync-no-data/template.marko
Normal file
@ -0,0 +1 @@
|
||||
- Hello!
|
||||
8
test/autotests/api/renderSync-no-data/test.js
Normal file
8
test/autotests/api/renderSync-no-data/test.js
Normal file
@ -0,0 +1,8 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
var output = template.renderSync();
|
||||
expect(output).to.equal('Hello!');
|
||||
done();
|
||||
};
|
||||
8
test/autotests/api/renderSync/test.js
Normal file
8
test/autotests/api/renderSync/test.js
Normal file
@ -0,0 +1,8 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var template = marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
var output = template.renderSync({ name: 'John' });
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
};
|
||||
21
test/autotests/api/require-compiled-template/test.js
Normal file
21
test/autotests/api/require-compiled-template/test.js
Normal file
@ -0,0 +1,21 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
// Load the JS file to ensure the hello.marko.js file is created
|
||||
marko.load(nodePath.join(__dirname, 'template.marko'));
|
||||
|
||||
var templateModule = require(nodePath.join(__dirname, 'template.marko.js'));
|
||||
|
||||
var template = marko.load(templateModule);
|
||||
template.render({
|
||||
name: 'John'
|
||||
},
|
||||
function(err, output) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
};
|
||||
18
test/autotests/api/require-render-callback/test.js
Normal file
18
test/autotests/api/require-render-callback/test.js
Normal file
@ -0,0 +1,18 @@
|
||||
var nodePath = require('path');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var templatePath = nodePath.join(__dirname, 'template.marko');
|
||||
var template = require(templatePath);
|
||||
template.render(
|
||||
{
|
||||
name: 'John'
|
||||
},
|
||||
function(err, output) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
};
|
||||
@ -0,0 +1 @@
|
||||
- Hello ${data.name}!
|
||||
25
test/autotests/api/require-render-to-stream/test.js
Normal file
25
test/autotests/api/require-render-to-stream/test.js
Normal file
@ -0,0 +1,25 @@
|
||||
var nodePath = require('path');
|
||||
var through = require('through');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var output = '';
|
||||
var outStream = through(function write(data) {
|
||||
output += data;
|
||||
});
|
||||
|
||||
outStream.on('end', function() {
|
||||
expect(output).to.equal('Hello John!');
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
var template = require(nodePath.join(__dirname, 'template.marko'));
|
||||
template.stream(
|
||||
{
|
||||
name: 'John'
|
||||
})
|
||||
.pipe(outStream)
|
||||
.on('error', function(e) {
|
||||
done(e);
|
||||
});
|
||||
};
|
||||
1
test/autotests/api/write-to-disk-load/template.marko
Normal file
1
test/autotests/api/write-to-disk-load/template.marko
Normal file
@ -0,0 +1 @@
|
||||
- Hello ${data.name}!
|
||||
14
test/autotests/api/write-to-disk-load/test.js
Normal file
14
test/autotests/api/write-to-disk-load/test.js
Normal file
@ -0,0 +1,14 @@
|
||||
var nodePath = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var compiledPath;
|
||||
|
||||
var templatePath = nodePath.join(__dirname, 'template.marko');
|
||||
compiledPath = nodePath.join(__dirname, 'template.marko.js');
|
||||
var template = marko.load(templatePath);
|
||||
expect(fs.existsSync(compiledPath)).to.equal(true);
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
|
||||
done();
|
||||
};
|
||||
1
test/autotests/api/write-to-disk-require/template.marko
Normal file
1
test/autotests/api/write-to-disk-require/template.marko
Normal file
@ -0,0 +1 @@
|
||||
- Hello ${data.name}!
|
||||
19
test/autotests/api/write-to-disk-require/test.js
Normal file
19
test/autotests/api/write-to-disk-require/test.js
Normal file
@ -0,0 +1,19 @@
|
||||
var nodePath = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
exports.check = function(marko, markoCompiler, expect, done) {
|
||||
var compiledPath;
|
||||
|
||||
try {
|
||||
var templatePath = nodePath.join(__dirname, 'template.marko');
|
||||
compiledPath = nodePath.join(__dirname, 'template.marko.js');
|
||||
var template = require(templatePath);
|
||||
delete require.cache[templatePath];
|
||||
expect(fs.existsSync(compiledPath)).to.equal(true);
|
||||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!');
|
||||
} finally {
|
||||
fs.unlinkSync(compiledPath);
|
||||
}
|
||||
|
||||
done();
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user