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

raz

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raz - npm Package Compare versions

Comparing version 0.0.40 to 0.0.41

test/razor.test.views/sections/_partial.raz

9

core/errors/errors.en.js

@@ -134,2 +134,7 @@ const RazorError = require('./RazorError');

sectionIsNotCompiled(sectionName, filePath) {
var message = `You try to render the section '${sectionName}' from the '${filePath}' view. This section has not been compiled yet. Make sure it is defined before the '@Html.section' method is called.`;
return RazorError.new({ message, info: this.info, capture: this.sectionIsNotCompiled });
}
sectionsAlreadyRendered(sectionName, renderedBy, attemptedBy) {

@@ -140,4 +145,4 @@ var message = `Sections named '${sectionName}' have already been rendered by '${renderedBy}'. There is an atempt to rendered it again by '${attemptedBy}'.`;

sectionNeverRendered(sectionName,) {
var message = `Section '${sectionName}' has never been rendered. If a section exists it must be rendered.`;
sectionNeverRendered(sectionName, viewPath) {
var message = `Section '${sectionName}' in '${viewPath}' has never been rendered. If a section exists it must be rendered.`;
return RazorError.new({ message, info: this.info, capture: this.sectionBeenRendered });

@@ -144,0 +149,0 @@ }

@@ -102,8 +102,12 @@ 'use strict';

this.__sec = function (name) { // in section
if (!sectionName)
if (!sectionName) {
sectionName = name;
else if (sectionName === name)
}
else if (sectionName === name) {
sections[sectionName][args.filePath].compiled = true;
sectionName = null;
else
}
else {
throw new Error(`Unexpected section name = '${name}'.`); // Cannot be tested via user-inputs.
}
};

@@ -161,2 +165,6 @@

let sec = secGroup[key];
if (!sec.compiled)
throw args.er.sectionIsNotCompiled(name, args.filePath); // [#3.2]
html += sec.html;

@@ -171,8 +179,6 @@ }

if (required)
throw args.er.sectionIsNotFound(name, args.filePath); // TESTME:
return '';
throw args.er.sectionIsNotFound(name, args.filePath); // [#3.3]
}
// TODO: throw error that section was not rendered.
return '';
};

@@ -397,6 +403,8 @@

if (sections.hasOwnProperty(key)) {
let sec = sections[key];
if (!sec.renderedBy)
throw this.er.sectionNeverRendered(key);
let secGroup = sections[key];
if (!secGroup.renderedBy){
let sec = secGroup[Object.keys(secGroup)[0]]; // just any section from the group
throw this.er.sectionNeverRendered(key, sec.filePath);
}
}

@@ -403,0 +411,0 @@ }

{
"name": "raz",
"description": "Razor-like syntax for templating views in Express framework by mixing HTML with JavaScript.",
"version": "0.0.40",
"version": "0.0.41",
"author": {

@@ -6,0 +6,0 @@ "name": "Sergey",

@@ -407,3 +407,3 @@ (function () {

}`,
expected: '\n<div>test</div>\n'
error: `Section 'Footer' in 'Code 49' has never been rendered. If a section exists it must be rendered.`
},

@@ -410,0 +410,0 @@ {

@@ -26,9 +26,2 @@ ////////////////////////////////////////////

// Testing view names.
const views = {
// partial: getViewName("_partial"),
// renderFile: getViewName(razor.renderFile.name),
// findViewStart: getViewName(razor.findViewStarts.name),
// findPartialSync: getViewName(razor.findPartialSync.name),
}

@@ -220,2 +213,122 @@ // It doesn't work with prototype methods.

///////////////////
// SECTIONS
//////////////////
describe(`SECTIONS`, () => {
describe(`[#3 : declare & render section within one view]`, () => {
let okPath = "sections/ok/";
let errorPath = "sections/error/";
// [#3.1] : correct order
{
let viewName = "oneViewSection.raz";
let filePath = joinViewPath(okPath, viewName);
it(`[#3.1 | OK: correct order ]`, (done) => {
razor({ h1: "HEADERS" }).renderFile(filePath, (err, html) => {
expect(err).not.to.exist;
expect(html).to.exist;
expect(html).to.have.string("<h1>HEADERS</h1>");
done();
});
});
}
// [#3.1.1] : not found and not required
{
let viewName = "notRequired.raz";
let filePath = joinViewPath(okPath, viewName);
it(`[#3.1.1 | OK: not found and not required ]`, (done) => {
razor().renderFile(filePath, (err, html) => {
expect(err).not.to.exist;
expect(html).to.exist;
done();
});
});
}
// [#3.2] : reverse order
{
let viewName = "oneViewSectionReverseOrder.raz";
let filePath = joinViewPath(errorPath, viewName);
it(`[#3.2 | ERROR: reverse order ]`, (done) => {
razor({ h1: "STYLES" }).renderFile(filePath, (err, html) => {
expect(html).not.to.exist;
expect(err).to.exist;
expectError2({
err,
errMes: `You try to render the section 'Headers' from the '${filePath}' view. This section has not been compiled yet. Make sure it is defined before the '@Html.section' method is called.`,
});
done();
});
});
}
// [#3.3] : section is not found
{
let viewName = "sectionIsNotFound.raz";
let filePath = joinViewPath(errorPath, viewName);
let sectionName = "Styles";
it(`[#3.3 | ERROR: section is not found ]`, (done) => {
razor({ sectionName }).renderFile(filePath, (err, html) => {
expect(html).not.to.exist;
expect(err).to.exist;
expectError2({
err,
errMes: `View '${filePath}' requires the section '${sectionName}' which cannot be found.`,
});
done();
});
});
}
// [#3.4] : section is already rendered
{
let viewName = "sectionAlreadyRendered.raz";
let filePath = joinViewPath(errorPath, viewName);
let sectionName = "Headers";
it(`[#3.4 | ERROR: section is already rendered ]`, (done) => {
razor().renderFile(filePath, (err, html) => {
expect(html).not.to.exist;
expect(err).to.exist;
expectError2({
err,
errMes: `Sections named '${sectionName}' have already been rendered by '${filePath}'. There is an atempt to rendered it again by '${filePath}'.`,
});
done();
});
});
}
// [#3.5] : section is vever rendered
{
let viewName = "sectionNeverRendered.raz";
let filePath = joinViewPath(errorPath, viewName);
let sectionName = "Headers";
it(`[#3.5 | ERROR: section is vever rendered ]`, (done) => {
razor().renderFile(filePath, (err, html) => {
expect(html).not.to.exist;
expect(err).to.exist;
expectError2({
err,
errMes: `Section '${sectionName}' in '${filePath}' has never been rendered. If a section exists it must be rendered.`,
});
done();
});
});
}
});
// describe(`[#4 : declare & render section in different views]`, () => {
// // [#4.1] : section from partial views is rendered only once
// {
// let viewName = "index.raz";
// let filePath = joinViewPath("sections", viewName);
// it(`[#4.1 | OK: section from partial views is rendered only once ]`, (done) => {
// razor({ h1: "HEADERS" }).renderFile(filePath, (err, html) => {
// expect(err).not.to.exist;
// expect(html).to.exist;
// expect(html).to.have.string("<h1>HEADERS</h1>");
// done();
// });
// });
// }
// });
});
function expectError(err, errorViewName, method, errCode) {

@@ -230,2 +343,14 @@ expect(err).to.exist;

function expectError2({err, errMes, method}) {
expect(err).to.exist;
expect(err).to.be.an.instanceOf(RazorError);
if (method)
expect(err.stack).to.have.string(`at Razor.${method} `);
if (errMes)
expect(err.message).to.have.string(errMes);
//expect(err.data.filename).to.endsWith(errorViewName);
}
function expectPartialViewNotFound(err, errorView, partialView, method) {

@@ -267,2 +392,6 @@ expect(err).to.exist;

function joinViewPath(viewPath, viewName) {
return path.join(viewsPath, viewPath, viewName);
}
function viewErrorPath(viewName) {

@@ -269,0 +398,0 @@ return path.join(viewsPath, "errors", viewName);

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