mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
* update autotest api and first few test suites * refactor components-browser to use the new autotest api * minor changes to update adjustIndent and components-pages to new autotest api * refactor and combine async-render, deprecated-async-fragments, and render suites * migrate compiler tests to new autotest runner * migrate components-compilation tests to use new autotest api * migrate most remaining test runners to new autotest api * update adjustIndent * migrate express tests to new autotest api * switch from compare to snapshot * move versions into directory * remove snapshot sequences, prefix to name, suffix to ext * refactor autotest * keep node 4 happy: don't use destructured parameters * use strict * update contributing document to reflect new autotest api * better snapshot errors with clickable path * remove old vdomSkip property, fix some normalization in the render test runner, skip only tests that need to be skipped * for generated vdom expectations use expected.html instead of rerendering the html template, update expected files that had editor added newlines at the end * remove half-finished test that was intended to replace another test (render/fixtures/preserveWhitespace-load-option) - we'll keep the original
73 lines
2.0 KiB
JavaScript
73 lines
2.0 KiB
JavaScript
"use strict";
|
|
|
|
require("../__util__/test-init");
|
|
|
|
var chai = require("chai");
|
|
chai.config.includeStack = true;
|
|
var expect = require("chai").expect;
|
|
|
|
var path = require("path");
|
|
var compiler = require("../../compiler");
|
|
var builder = compiler.createBuilder();
|
|
var autotest = require("../autotest");
|
|
|
|
var CompileContext = require("marko/compiler/CompileContext");
|
|
var CodeGenerator = require("marko/compiler/CodeGenerator");
|
|
var CodeWriter = require("marko/compiler/CodeWriter");
|
|
|
|
function createCodeGenerator(context) {
|
|
return new CodeGenerator(context);
|
|
}
|
|
|
|
function createCodeWriter(context) {
|
|
return new CodeWriter(context, builder);
|
|
}
|
|
|
|
autotest("fixtures", fixture => {
|
|
let test = fixture.test;
|
|
let resolve = fixture.resolve;
|
|
let snapshot = fixture.snapshot;
|
|
test(done => {
|
|
var main = require(resolve("index.js"));
|
|
var generateCodeFunc = main;
|
|
|
|
var context = new CompileContext(
|
|
"dummy",
|
|
resolve("dummy.marko"),
|
|
builder
|
|
);
|
|
var codegen = createCodeGenerator(context);
|
|
var codeWriter = createCodeWriter(context);
|
|
|
|
var ast = generateCodeFunc(builder, codegen);
|
|
var finalAST = codegen.generateCode(ast);
|
|
|
|
codeWriter.write(finalAST);
|
|
|
|
var actualSrc = codeWriter.getCode();
|
|
actualSrc = actualSrc.replace(/marko\/dist\//g, "marko/src/");
|
|
|
|
snapshot(actualSrc, { ext: ".js" });
|
|
done();
|
|
});
|
|
});
|
|
|
|
describe("codegen", function() {
|
|
it("should not allow a return outside a function", function() {
|
|
let builder = compiler.createBuilder();
|
|
|
|
var context = new CompileContext(
|
|
"dummy",
|
|
path.join(__dirname, "dummy.marko"),
|
|
builder
|
|
);
|
|
var codegen = createCodeGenerator(context);
|
|
|
|
var rootNode = builder.program([builder.returnStatement("foo")]);
|
|
|
|
expect(function() {
|
|
codegen.generateCode(rootNode);
|
|
}).to.throw('"return" not allowed outside a function body');
|
|
});
|
|
});
|