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

@stylable/core-test-kit

Package Overview
Dependencies
Maintainers
7
Versions
188
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stylable/core-test-kit - npm Package Compare versions

Comparing version 4.10.2 to 4.10.3

dist/test-stylable-core.d.ts

1

dist/index.d.ts

@@ -8,2 +8,3 @@ export { Diagnostic, expectAnalyzeDiagnostics, expectTransformDiagnostics, findTestLocations, shouldReportNoDiagnostics, } from './diagnostics';

export { testInlineExpects, testInlineExpectsErrors } from './inline-expectation';
export { testStylableCore } from './test-stylable-core';
//# sourceMappingURL=index.d.ts.map

4

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.testInlineExpectsErrors = exports.testInlineExpects = exports.matchRuleAndDeclaration = exports.matchAllRulesAndDeclarations = exports.styleRules = exports.mediaQuery = exports.matchCSSMatchers = exports.flatMatch = exports.generateStylableEnvironment = exports.processSource = exports.generateStylableRoot = exports.generateStylableResult = exports.generateStylableExports = exports.generateInfra = exports.createTransformer = exports.createProcess = exports.shouldReportNoDiagnostics = exports.findTestLocations = exports.expectTransformDiagnostics = exports.expectAnalyzeDiagnostics = void 0;
exports.testStylableCore = exports.testInlineExpectsErrors = exports.testInlineExpects = exports.matchRuleAndDeclaration = exports.matchAllRulesAndDeclarations = exports.styleRules = exports.mediaQuery = exports.matchCSSMatchers = exports.flatMatch = exports.generateStylableEnvironment = exports.processSource = exports.generateStylableRoot = exports.generateStylableResult = exports.generateStylableExports = exports.generateInfra = exports.createTransformer = exports.createProcess = exports.shouldReportNoDiagnostics = exports.findTestLocations = exports.expectTransformDiagnostics = exports.expectAnalyzeDiagnostics = void 0;
var diagnostics_1 = require("./diagnostics");

@@ -31,2 +31,4 @@ Object.defineProperty(exports, "expectAnalyzeDiagnostics", { enumerable: true, get: function () { return diagnostics_1.expectAnalyzeDiagnostics; } });

Object.defineProperty(exports, "testInlineExpectsErrors", { enumerable: true, get: function () { return inline_expectation_1.testInlineExpectsErrors; } });
var test_stylable_core_1 = require("./test-stylable-core");
Object.defineProperty(exports, "testStylableCore", { enumerable: true, get: function () { return test_stylable_core_1.testStylableCore; } });
//# sourceMappingURL=index.js.map

@@ -42,2 +42,3 @@ import type { StylableMeta } from '@stylable/core';

unsupportedNode: (testType: string, nodeType: string, label?: string) => string;
removedNode: (nodeType: string, label?: string) => string;
selector: (expectedSelector: string, actualSelector: string, label?: string) => string;

@@ -53,2 +54,3 @@ declarations: (expectedDecl: string, actualDecl: string, selector: string, label?: string) => string;

deprecatedRootInputNotSupported: (expectation: string) => string;
transformRemoved: (nodeType: string, label?: string) => string;
diagnosticsMalformed: (type: string, expectation: string, label?: string) => string;

@@ -55,0 +57,0 @@ diagnosticsNotFound: (type: string, message: string, label?: string) => string;

@@ -76,2 +76,3 @@ "use strict";

const nodeSrc = testCommentSrc.next();
const isRemoved = isRemovedFromTarget(nodeTarget, nodeSrc);
if (nodeTarget || nodeSrc) {

@@ -104,3 +105,3 @@ while (input.length) {

else {
const result = tests[testScope](context, testInput.trim(), nodeTarget, nodeSrc);
const result = tests[testScope](context, testInput.trim(), isRemoved ? undefined : nodeTarget, nodeSrc);
result.type = testScope;

@@ -125,3 +126,3 @@ errors.push(...result.errors);

function checkTest(context, expectation, targetNode, srcNode) {
const type = targetNode === null || targetNode === void 0 ? void 0 : targetNode.type;
const type = (srcNode === null || srcNode === void 0 ? void 0 : srcNode.type) || (targetNode === null || targetNode === void 0 ? void 0 : targetNode.type);
switch (type) {

@@ -142,3 +143,3 @@ case `rule`: {

}
function ruleTest(context, expectation, targetNode, _srcNode) {
function ruleTest(context, expectation, targetNode, srcNode) {
var _a;

@@ -150,3 +151,9 @@ const result = {

};
const { msg, ruleIndex, expectedSelector, expectedBody } = expectation.match(/(?<msg>\(.*\))*(\[(?<ruleIndex>\d+)\])*(?<expectedSelector>[^{}]*)\s*(?<expectedBody>.*)/s).groups;
const { msg, ruleIndex, expectedSelector, expectedBody } = expectation.match(/(?<msg>\([^)]*\))*(\[(?<ruleIndex>\d+)\])*(?<expectedSelector>[^{}]*)\s*(?<expectedBody>.*)/s).groups;
const prefix = msg ? msg + `: ` : ``;
if (!targetNode) {
// ToDo: maybe support nodes that are removed from target and leaves mixins
result.errors.push(exports.testInlineExpectsErrors.removedNode(srcNode.type, prefix));
return result;
}
let testNode = targetNode;

@@ -187,3 +194,2 @@ // get mixed-in rule

}
const prefix = msg ? msg + `: ` : ``;
if (testNode.selector !== expectedSelector.trim()) {

@@ -213,3 +219,3 @@ result.errors.push(exports.testInlineExpectsErrors.selector(expectedSelector.trim(), testNode.selector, prefix));

}
function atRuleTest(_context, expectation, targetNode, _srcNode) {
function atRuleTest(_context, expectation, targetNode, srcNode) {
const result = {

@@ -227,3 +233,7 @@ type: `@atrule`,

const prefix = msg ? msg + `: ` : ``;
if (targetNode.type === `atrule`) {
if (!targetNode) {
// ToDo: maybe support nodes that are removed from target and leaves mixins
result.errors.push(exports.testInlineExpectsErrors.removedNode(srcNode.type, prefix));
}
else if (targetNode.type === `atrule`) {
if (targetNode.params !== expectedParams.trim()) {

@@ -238,3 +248,3 @@ result.errors.push(exports.testInlineExpectsErrors.atruleParams(expectedParams.trim(), targetNode.params, prefix));

}
function declTest(_context, expectation, targetNode, _srcNode) {
function declTest(_context, expectation, targetNode, srcNode) {
const result = {

@@ -249,3 +259,6 @@ type: `@decl`,

value = value.trim();
if (!prop || !value) {
if (!targetNode) {
result.errors.push(exports.testInlineExpectsErrors.removedNode(srcNode.type, label));
}
else if (!prop || !value) {
result.errors.push(exports.testInlineExpectsErrors.declMalformed(prop, value, label));

@@ -269,2 +282,19 @@ }

function transformTest(context, expectation, targetNode, srcNode) {
var _a, _b, _c, _d;
// check node is removed in transformation
const matchResult = expectation.match(/-remove(?<label>\([^)]*\))?/);
if (matchResult) {
const node = srcNode;
let { label } = matchResult.groups;
label = label ? label + `: ` : ``;
const isRemoved = !targetNode ||
((_a = targetNode.source) === null || _a === void 0 ? void 0 : _a.start) !== ((_b = srcNode.source) === null || _b === void 0 ? void 0 : _b.start) ||
((_c = targetNode.source) === null || _c === void 0 ? void 0 : _c.end) !== ((_d = srcNode.source) === null || _d === void 0 ? void 0 : _d.end);
return {
type: `@transform`,
expectation,
errors: isRemoved ? [] : [exports.testInlineExpectsErrors.transformRemoved(node.type, label)],
};
}
// check transform diagnostics
return diagnosticTest(`transform`, context, expectation, targetNode, srcNode);

@@ -330,2 +360,8 @@ }

}
function isRemovedFromTarget(target, source) {
var _a, _b, _c, _d;
return (!target ||
((_a = target.source) === null || _a === void 0 ? void 0 : _a.start) !== ((_b = source.source) === null || _b === void 0 ? void 0 : _b.start) ||
((_c = target.source) === null || _c === void 0 ? void 0 : _c.end) !== ((_d = source.source) === null || _d === void 0 ? void 0 : _d.end));
}
function getNextMixinRule(originRule, count) {

@@ -344,2 +380,3 @@ let current = originRule;

unsupportedNode: (testType, nodeType, label = ``) => `${label}unsupported type "${testType}" for "${nodeType}"`,
removedNode: (nodeType, label = ``) => `${label}fail to check transformation on removed node with type "${nodeType}"`,
selector: (expectedSelector, actualSelector, label = ``) => `${label}expected "${actualSelector}" to transform to "${expectedSelector}"`,

@@ -365,2 +402,3 @@ declarations: (expectedDecl, actualDecl, selector, label = ``) => `${label}expected ${selector} to have declaration {${expectedDecl}}, but got {${actualDecl}}`,

deprecatedRootInputNotSupported: (expectation) => `"${expectation}" is not supported for with the used input, try calling testInlineExpects(generateStylableResults())`,
transformRemoved: (nodeType, label = ``) => `${label} expected ${nodeType} to be removed, but it was kept after transform`,
diagnosticsMalformed: (type, expectation, label = ``) => `${label}malformed @${type} expectation "@${type}${expectation}". format should be: "@${type}-[severity] diagnostic message"`,

@@ -367,0 +405,0 @@ diagnosticsNotFound: (type, message, label = ``) => `${label}${type} diagnostics not found for "${message}"`,

{
"name": "@stylable/core-test-kit",
"version": "4.10.2",
"version": "4.10.3",
"description": "Stylable core test-kit",

@@ -11,3 +11,3 @@ "main": "dist/index.js",

"@file-services/memory": "^5.7.1",
"@stylable/core": "^4.10.2",
"@stylable/core": "^4.10.3",
"chai": "^4.3.4",

@@ -14,0 +14,0 @@ "flat": "^5.0.2",

@@ -5,2 +5,71 @@ # @stylable/core-test-kit

## `testStylableCore`
Use `import {testStylableCore} from '@stylable/core-test-kit'` to test core analysis, transformation, diagnostics and symbols. All stylable files are checked for [inline expectations](#inline-expectations-syntax):
**single entry**
```js
// source + inline expectations
const { sheets } = testStylableCore(`
/* @rule .entry__root */
.root {}
`);
// single entry is mapped to `/entry.st.css`
const { meta, exports } = sheets[`/entry.st.css`];
```
**multiple files**
```js
// source + inline expectations
const { sheets } = testStylableCore({
'/entry.st.css': `
@st-import Comp from './comp.st.css';
/* @rule .entry__root .comp__root */
.root Comp {}
`,
'/comp.st.css': `
/* @rule .comp__root */
.root {}
`
});
// sheets results ({meta, exports})
const entryResults = sheets[`/entry.st.css`];
const compResults = sheets[`/comp.st.css`];
```
**stylable config**
```js
testStylableCore({
'/a.st.css': ``,
'/b.st.css': ``,
'/c.st.css': ``,
}, {
entries: [`/b.st.css`, `/c.st.css`] // list of entries to transform (in order)
stylableConfig: {
projectRoot: string, // defaults to `/`
resolveNamespace: (ns: string) => string, // defaults to no change
requireModule: (path: string) => any // defaults to naive CJS eval
filesystem: IFileSystem, // @file-services/types
// ...other stylable configurations
}
});
```
**expose infra**
```js
const { stylable, fs } = testStylableCore(``);
// add a file
fs.writeFileSync(
`/new.st.css`,
`
@st-import [part] from './entry.st.css';
.part {}
`
);
// transform new file
const { meta, exports } = stylable.transform(stylable.process(`/new.st.css`));
```
## Inline expectations syntax

@@ -127,4 +196,10 @@

Removed in transformation - `@transform-remove`
```css
/* @transform-remove */
@import X from './x.st.css';
```
## License
Copyright (c) 2019 Wix.com Ltd. All Rights Reserved. Use of this source code is governed by a [MIT license](./LICENSE).

@@ -27,1 +27,2 @@ export {

export { testInlineExpects, testInlineExpectsErrors } from './inline-expectation';
export { testStylableCore } from './test-stylable-core';

@@ -91,2 +91,3 @@ import { matchDiagnostic } from './diagnostics';

const nodeSrc = testCommentSrc.next() as AST;
const isRemoved = isRemovedFromTarget(nodeTarget, nodeSrc);
if (nodeTarget || nodeSrc) {

@@ -127,3 +128,3 @@ while (input.length) {

testInput.trim(),
nodeTarget,
isRemoved ? undefined : nodeTarget,
nodeSrc

@@ -149,4 +150,9 @@ );

function checkTest(context: Context, expectation: string, targetNode: AST, srcNode: AST): Test {
const type = targetNode?.type;
function checkTest(
context: Context,
expectation: string,
targetNode: AST | undefined,
srcNode: AST
): Test {
const type = srcNode?.type || targetNode?.type;
switch (type) {

@@ -167,3 +173,8 @@ case `rule`: {

}
function ruleTest(context: Context, expectation: string, targetNode: AST, _srcNode: AST): Test {
function ruleTest(
context: Context,
expectation: string,
targetNode: AST | undefined,
srcNode: AST
): Test {
const result: Test = {

@@ -175,4 +186,10 @@ type: `@rule`,

const { msg, ruleIndex, expectedSelector, expectedBody } = expectation.match(
/(?<msg>\(.*\))*(\[(?<ruleIndex>\d+)\])*(?<expectedSelector>[^{}]*)\s*(?<expectedBody>.*)/s
/(?<msg>\([^)]*\))*(\[(?<ruleIndex>\d+)\])*(?<expectedSelector>[^{}]*)\s*(?<expectedBody>.*)/s
)!.groups!;
const prefix = msg ? msg + `: ` : ``;
if (!targetNode) {
// ToDo: maybe support nodes that are removed from target and leaves mixins
result.errors.push(testInlineExpectsErrors.removedNode(srcNode.type, prefix));
return result;
}
let testNode: AST = targetNode;

@@ -215,3 +232,3 @@ // get mixed-in rule

}
const prefix = msg ? msg + `: ` : ``;
if (testNode.selector !== expectedSelector.trim()) {

@@ -253,3 +270,8 @@ result.errors.push(

}
function atRuleTest(_context: Context, expectation: string, targetNode: AST, _srcNode: AST): Test {
function atRuleTest(
_context: Context,
expectation: string,
targetNode: AST | undefined,
srcNode: AST
): Test {
const result: Test = {

@@ -267,3 +289,6 @@ type: `@atrule`,

const prefix = msg ? msg + `: ` : ``;
if (targetNode.type === `atrule`) {
if (!targetNode) {
// ToDo: maybe support nodes that are removed from target and leaves mixins
result.errors.push(testInlineExpectsErrors.removedNode(srcNode.type, prefix));
} else if (targetNode.type === `atrule`) {
if (targetNode.params !== expectedParams.trim()) {

@@ -283,3 +308,8 @@ result.errors.push(

}
function declTest(_context: Context, expectation: string, targetNode: AST, _srcNode: AST): Test {
function declTest(
_context: Context,
expectation: string,
targetNode: AST | undefined,
srcNode: AST
): Test {
const result: Test = {

@@ -296,3 +326,5 @@ type: `@decl`,

value = value.trim();
if (!prop || !value) {
if (!targetNode) {
result.errors.push(testInlineExpectsErrors.removedNode(srcNode.type, label));
} else if (!prop || !value) {
result.errors.push(testInlineExpectsErrors.declMalformed(prop, value, label));

@@ -312,6 +344,33 @@ } else if (targetNode.type === `decl`) {

}
function analyzeTest(context: Context, expectation: string, targetNode: AST, srcNode: AST): Test {
function analyzeTest(
context: Context,
expectation: string,
targetNode: AST | undefined,
srcNode: AST
): Test {
return diagnosticTest(`analyze`, context, expectation, targetNode, srcNode);
}
function transformTest(context: Context, expectation: string, targetNode: AST, srcNode: AST): Test {
function transformTest(
context: Context,
expectation: string,
targetNode: AST | undefined,
srcNode: AST
): Test {
// check node is removed in transformation
const matchResult = expectation.match(/-remove(?<label>\([^)]*\))?/);
if (matchResult) {
const node = srcNode;
let { label } = matchResult.groups!;
label = label ? label + `: ` : ``;
const isRemoved =
!targetNode ||
targetNode.source?.start !== srcNode.source?.start ||
targetNode.source?.end !== srcNode.source?.end;
return {
type: `@transform`,
expectation,
errors: isRemoved ? [] : [testInlineExpectsErrors.transformRemoved(node.type, label)],
};
}
// check transform diagnostics
return diagnosticTest(`transform`, context, expectation, targetNode, srcNode);

@@ -323,3 +382,3 @@ }

expectation: string,
_targetNode: AST,
_targetNode: AST | undefined,
srcNode: AST

@@ -394,2 +453,10 @@ ): Test {

function isRemovedFromTarget(target: AST, source: AST) {
return (
!target ||
target.source?.start !== source.source?.start ||
target.source?.end !== source.source?.end
);
}
function getNextMixinRule(originRule: postcss.Rule, count: number) {

@@ -411,2 +478,4 @@ let current: postcss.Node | undefined = originRule;

`${label}unsupported type "${testType}" for "${nodeType}"`,
removedNode: (nodeType: string, label = ``) =>
`${label}fail to check transformation on removed node with type "${nodeType}"`,
selector: (expectedSelector: string, actualSelector: string, label = ``) =>

@@ -436,2 +505,4 @@ `${label}expected "${actualSelector}" to transform to "${expectedSelector}"`,

`"${expectation}" is not supported for with the used input, try calling testInlineExpects(generateStylableResults())`,
transformRemoved: (nodeType: string, label = ``) =>
`${label} expected ${nodeType} to be removed, but it was kept after transform`,
diagnosticsMalformed: (type: string, expectation: string, label = ``) =>

@@ -438,0 +509,0 @@ `${label}malformed @${type} expectation "@${type}${expectation}". format should be: "@${type}-[severity] diagnostic message"`,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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