New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kss

Package Overview
Dependencies
Maintainers
3
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kss - npm Package Compare versions

Comparing version 3.0.0-beta.4 to 3.0.0-beta.5

20

builder/base/twig/kss_builder_base_twig.js

@@ -100,2 +100,10 @@ 'use strict';

// We need the ability to reset the template registry since the global
// Twig object is the same object every time it is require()d.
this.Twig.registryReset = (function() {
this.extend(function(Twig) {
Twig.Templates.registry = {};
});
}).bind(this.Twig);
// Collect the namespaces to be used by Twig.

@@ -114,3 +122,3 @@ this.namespaces = {

// Promisify Twig.twig().
this.Twig.twigAsync = (options) => {
this.Twig.twigAsync = (function(options) {
return new Promise((resolve, reject) => {

@@ -128,3 +136,3 @@ // Use our Promise's functions.

try {
resolve(this.Twig.twig(options));
resolve(this.twig(options));
} catch (error) {

@@ -135,6 +143,6 @@ // istanbul ignore next

} else {
this.Twig.twig(options);
this.twig(options);
}
});
};
}).bind(this.Twig);

@@ -222,2 +230,6 @@ if (this.options.verbose) {

// Reset the Twig template registry so KSS can be run in a "watch" task that
// does not destroy the Node.js environment between builds.
this.Twig.registryReset();
let buildTasks = [];

@@ -224,0 +236,0 @@

2

package.json
{
"name": "kss",
"version": "3.0.0-beta.4",
"version": "3.0.0-beta.5",
"description": "The Node.js port of KSS: A methodology for documenting CSS and building style guides",

@@ -5,0 +5,0 @@ "homepage": "http://kss-node.github.io/kss-node",

@@ -6,4 +6,3 @@ /* eslint-disable max-nested-callbacks,no-regex-spaces */

const cli = require('../lib/cli'),
mockStream = require('mock-utf8-stream'),
Twig = require('twig');
mockStream = require('mock-utf8-stream');

@@ -25,7 +24,2 @@ const API = '3.0';

// Empty the Twig template registry before running each test.
Twig.extend(function(Twig) {
Twig.Templates.registry = {};
});
return cli({

@@ -32,0 +26,0 @@ stdout: stdout,

@@ -9,44 +9,46 @@ /* eslint-disable max-nested-callbacks */

const testBuilder = function(options) {
options = options || {};
class TestKssBuilderBaseExample extends KssBuilderBaseExample {
constructor(options) {
super();
let builder = new KssBuilderBaseExample();
options = options || {};
// For our tests, feed kss() log functions that mock stdout and stderr so we
// can capture the output easier.
options.testStreams = {};
options.testStreams.stdout = new mockStream.MockWritableStream();
options.testStreams.stderr = new mockStream.MockWritableStream();
options.testStreams.stdout.startCapture();
options.testStreams.stderr.startCapture();
options.logFunction = function() {
let message = '';
for (let i = 0; i < arguments.length; i++) {
message += arguments[i];
if (!options.builder) {
options.builder = path.resolve(__dirname, '..', 'builder', 'twig');
}
options.testStreams.stdout.write(message + '\n');
};
options.logErrorFunction = function(error) {
// Show the full error stack if the verbose option is used twice or more.
options.testStreams.stderr.write(((error.stack && options.verbose > 1) ? error.stack : error) + '\n');
};
builder.addOptions(options);
// For our tests, feed kss() log functions that mock stdout and stderr so we
// can capture the output easier.
this.testStreams = {};
this.testStreams.stdout = new mockStream.MockWritableStream();
this.testStreams.stderr = new mockStream.MockWritableStream();
this.testStreams.stdout.startCapture();
this.testStreams.stderr.startCapture();
options.logFunction = (function() {
let message = '';
for (let i = 0; i < arguments.length; i++) {
message += arguments[i];
}
this.testStreams.stdout.write(message + '\n');
}).bind(this);
options.logErrorFunction = (function(error) {
// Show the full error stack if the verbose option is used twice or more.
this.testStreams.stderr.write(((error.stack && options.verbose > 1) ? error.stack : error) + '\n');
}).bind(this);
builder.getTestOutput = function(pipe) {
let streams = this.getOptions('testStreams');
this.addOptions(options);
}
getTestOutput(pipe) {
if (typeof pipe === 'undefined') {
return {
stdout: streams.stdout.capturedData,
stderr: streams.stderr.capturedData
stdout: this.testStreams.stdout.capturedData,
stderr: this.testStreams.stderr.capturedData
};
} else {
return streams[pipe].capturedData;
return this.testStreams[pipe].capturedData;
}
};
}
}
return builder;
};
describe('KssBuilderBaseExample object API', function() {

@@ -73,3 +75,3 @@

it('should have a working clone() method', function() {
let builder = testBuilder(),
let builder = new TestKssBuilderBaseExample(),
destinationPath = path.resolve(__dirname, 'output', 'example');

@@ -82,3 +84,3 @@ return builder.clone('', destinationPath).then(() => {

it('should have a working prepare() method', function() {
let builder = testBuilder(),
let builder = new TestKssBuilderBaseExample(),
originalStyleGuide = new kss.KssStyleGuide({sections: [{header: 'Section One'}, {header: 'Section Two'}]});

@@ -94,3 +96,3 @@ return builder.prepare(originalStyleGuide).then(styleGuide => {

it('should have a working build() method', function() {
let builder = testBuilder(),
let builder = new TestKssBuilderBaseExample(),
originalStyleGuide = new kss.KssStyleGuide({sections: [{header: 'Section One'}, {header: 'Section Two'}]});

@@ -97,0 +99,0 @@ return builder.prepare(originalStyleGuide).then(styleGuide => {

@@ -9,44 +9,46 @@ /* eslint-disable max-nested-callbacks */

const testBuilder = function(options) {
options = options || {};
class TestKssBuilderBaseHandlebars extends KssBuilderBaseHandlebars {
constructor(options) {
super();
let builder = new KssBuilderBaseHandlebars();
options = options || {};
// For our tests, feed kss() log functions that mock stdout and stderr so we
// can capture the output easier.
options.testStreams = {};
options.testStreams.stdout = new mockStream.MockWritableStream();
options.testStreams.stderr = new mockStream.MockWritableStream();
options.testStreams.stdout.startCapture();
options.testStreams.stderr.startCapture();
options.logFunction = function() {
let message = '';
for (let i = 0; i < arguments.length; i++) {
message += arguments[i];
if (!options.builder) {
options.builder = path.resolve(__dirname, '..', 'builder', 'twig');
}
options.testStreams.stdout.write(message + '\n');
};
options.logErrorFunction = function(error) {
// Show the full error stack if the verbose option is used twice or more.
options.testStreams.stderr.write(((error.stack && options.verbose > 1) ? error.stack : error) + '\n');
};
builder.addOptions(options);
// For our tests, feed kss() log functions that mock stdout and stderr so we
// can capture the output easier.
this.testStreams = {};
this.testStreams.stdout = new mockStream.MockWritableStream();
this.testStreams.stderr = new mockStream.MockWritableStream();
this.testStreams.stdout.startCapture();
this.testStreams.stderr.startCapture();
options.logFunction = (function() {
let message = '';
for (let i = 0; i < arguments.length; i++) {
message += arguments[i];
}
this.testStreams.stdout.write(message + '\n');
}).bind(this);
options.logErrorFunction = (function(error) {
// Show the full error stack if the verbose option is used twice or more.
this.testStreams.stderr.write(((error.stack && options.verbose > 1) ? error.stack : error) + '\n');
}).bind(this);
builder.getTestOutput = function(pipe) {
let streams = this.getOptions('testStreams');
this.addOptions(options);
}
getTestOutput(pipe) {
if (typeof pipe === 'undefined') {
return {
stdout: streams.stdout.capturedData,
stderr: streams.stderr.capturedData
stdout: this.testStreams.stdout.capturedData,
stderr: this.testStreams.stderr.capturedData
};
} else {
return streams[pipe].capturedData;
return this.testStreams[pipe].capturedData;
}
};
}
}
return builder;
};
describe('KssBuilderBaseHandlebars object API', function() {

@@ -57,3 +59,3 @@ before(function() {

destination = path.resolve(__dirname, 'output', 'base_handlebars', 'build');
this.builder = testBuilder({
this.builder = new TestKssBuilderBaseHandlebars({
source: source,

@@ -117,3 +119,3 @@ destination: destination,

before(function() {
this.builderPrepared = testBuilder({
this.builderPrepared = new TestKssBuilderBaseHandlebars({
destination: path.resolve(__dirname, 'output', 'base_handlebars', 'prepare'),

@@ -136,3 +138,3 @@ builder: helperUtils.fixtures('builder-with-assets'),

it('outputs settings if the verbose option is set', function() {
let builder = testBuilder({
let builder = new TestKssBuilderBaseHandlebars({
extend: ['/dev/null/example1', '/dev/null/example2'],

@@ -176,3 +178,3 @@ verbose: true,

});
let builder = testBuilder();
let builder = new TestKssBuilderBaseHandlebars();
return builder.build(styleGuide).catch(error => {

@@ -210,3 +212,3 @@ return error;

let builder = testBuilder({
let builder = new TestKssBuilderBaseHandlebars({
source: helperUtils.fixtures('source-handlebars-builder-test'),

@@ -265,3 +267,3 @@ destination: path.resolve(__dirname, 'output', 'base_handlebars', 'build-no-verbose'),

let builder = testBuilder({
let builder = new TestKssBuilderBaseHandlebars({
source: helperUtils.fixtures('source-handlebars-builder-test'),

@@ -268,0 +270,0 @@ destination: path.resolve(__dirname, 'output', 'base_handlebars', 'buildPage'),

@@ -9,55 +9,57 @@ /* eslint-disable max-nested-callbacks */

const testBuilder = function(options) {
options = options || {};
class TestKssBuilderBaseTwig extends KssBuilderBaseTwig {
constructor(options) {
super();
let builder = new KssBuilderBaseTwig();
if (!options.builder) {
options.builder = path.resolve(__dirname, '..', 'builder', 'twig');
}
options = options || {};
// For our tests, feed kss() log functions that mock stdout and stderr so we
// can capture the output easier.
options.testStreams = {};
options.testStreams.stdout = new mockStream.MockWritableStream();
options.testStreams.stderr = new mockStream.MockWritableStream();
options.testStreams.stdout.startCapture();
options.testStreams.stderr.startCapture();
options.logFunction = function() {
let message = '';
for (let i = 0; i < arguments.length; i++) {
message += arguments[i];
if (!options.builder) {
options.builder = path.resolve(__dirname, '..', 'builder', 'twig');
}
options.testStreams.stdout.write(message + '\n');
};
options.logErrorFunction = function(error) {
// Show the full error stack if the verbose option is used twice or more.
options.testStreams.stderr.write(((error.stack && options.verbose > 1) ? error.stack : error) + '\n');
};
builder.addOptions(options);
// For our tests, feed kss() log functions that mock stdout and stderr so we
// can capture the output easier.
this.testStreams = {};
this.testStreams.stdout = new mockStream.MockWritableStream();
this.testStreams.stderr = new mockStream.MockWritableStream();
this.testStreams.stdout.startCapture();
this.testStreams.stderr.startCapture();
options.logFunction = (function() {
let message = '';
for (let i = 0; i < arguments.length; i++) {
message += arguments[i];
}
this.testStreams.stdout.write(message + '\n');
}).bind(this);
options.logErrorFunction = (function(error) {
// Show the full error stack if the verbose option is used twice or more.
this.testStreams.stderr.write(((error.stack && options.verbose > 1) ? error.stack : error) + '\n');
}).bind(this);
// The internal Twig variable is GLOBAL. This method allows the test to move
// the Twig registry for later inspection.
builder.saveRegistry = function() {
builder.Twig.extend(function(Twig) {
builder.registry = Twig.Templates.registry;
Twig.Templates.registry = {};
});
};
this.addOptions(options);
}
builder.getTestOutput = function(pipe) {
let streams = this.getOptions('testStreams');
getTestOutput(pipe) {
if (typeof pipe === 'undefined') {
return {
stdout: streams.stdout.capturedData,
stderr: streams.stderr.capturedData
stdout: this.testStreams.stdout.capturedData,
stderr: this.testStreams.stderr.capturedData
};
} else {
return streams[pipe].capturedData;
return this.testStreams[pipe].capturedData;
}
};
}
return builder;
};
// The internal Twig variable is GLOBAL and the global Twig template
// registry is reset each time any test's build() is run. So we copy the
// Twig registry for later inspection by our tests.
build(styleGuide) {
return super.build(styleGuide).then(styleGuide => {
this.Twig.extend(Twig => {
this.registry = Twig.Templates.registry;
});
return Promise.resolve(styleGuide);
});
}
}

@@ -69,3 +71,3 @@ describe('KssBuilderBaseTwig object API', function() {

destination = path.resolve(__dirname, 'output', 'base_twig', 'build');
this.builder = testBuilder({
this.builder = new TestKssBuilderBaseTwig({
source: source,

@@ -82,6 +84,4 @@ destination: destination,

}).then(styleGuide => {
this.builder.saveRegistry();
return this.builder.build(styleGuide);
}).then(() => {
this.builder.saveRegistry();
return Promise.all(

@@ -132,3 +132,3 @@ [

before(function() {
this.builderPrepared = testBuilder({
this.builderPrepared = new TestKssBuilderBaseTwig({
'destination': path.resolve(__dirname, 'output', 'base_twig', 'prepare'),

@@ -160,3 +160,3 @@ 'builder': helperUtils.fixtures('builder-twig-with-assets'),

it('outputs settings if the verbose option is set', function() {
let builder = testBuilder({
let builder = new TestKssBuilderBaseTwig({
extend: ['/dev/null/example1', '/dev/null/example2'],

@@ -209,3 +209,3 @@ verbose: true,

});
let builder = testBuilder();
let builder = new TestKssBuilderBaseTwig();
builder.addOptions({

@@ -215,6 +215,4 @@ destination: path.resolve(__dirname, 'output', 'base_twig', 'save-styleguide')

return builder.prepare(styleGuide).then(styleGuide => {
builder.saveRegistry();
return builder.build(styleGuide);
}).then(() => {
builder.saveRegistry();
expect(builder.styleGuide).to.deep.equal(styleGuide);

@@ -266,3 +264,3 @@ });

let builder = testBuilder({
let builder = new TestKssBuilderBaseTwig({
source: helperUtils.fixtures('source-twig-builder-test'),

@@ -275,6 +273,4 @@ destination: path.resolve(__dirname, 'output', 'base_twig', 'build-no-verbose'),

return builder.prepare(styleGuide).then(styleGuide => {
builder.saveRegistry();
return builder.build(styleGuide);
}).then(() => {
builder.saveRegistry();
expect(builder.getTestOutput('stdout')).to.include('WARNING: In section 4.3, 4.3.twig NOT FOUND!');

@@ -324,3 +320,3 @@ });

let builder = testBuilder({
let builder = new TestKssBuilderBaseTwig({
source: helperUtils.fixtures('source-twig-builder-test'),

@@ -333,10 +329,12 @@ destination: path.resolve(__dirname, 'output', 'base_twig', 'buildPage'),

return builder.prepare(styleGuide).then(styleGuide => {
// Instead of running builder.build(), we do 2 of its tasks manually:
// Instead of running builder.build(), we do 3 of its tasks manually:
// - save the style guide
// - reset the Twig template registry
// - compile the Twig template
builder.styleGuide = styleGuide;
builder.saveRegistry();
builder.Twig.extend(function(Twig) {
Twig.Templates.registry = {};
});
return builder.Twig.twigAsync({path: path.resolve(builder.options.builder, 'index.twig')});
}).then(template => {
builder.saveRegistry();
builder.templates = {};

@@ -343,0 +341,0 @@ builder.templates.index = template;

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