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.13.2 to 5.0.0-rc.1

10

dist/diagnostics.d.ts
import type { Position } from 'postcss';
import { DiagnosticType, StylableMeta, StylableResults } from '@stylable/core';
import { DiagnosticSeverity, StylableMeta, StylableResults } from '@stylable/core';
import { DiagnosticBase } from '@stylable/core/dist/index-internal';
import { Config } from './generate-test-util';
export interface Diagnostic {
severity?: DiagnosticType;
severity?: DiagnosticSeverity;
message: string;

@@ -43,2 +44,7 @@ file: string;

export declare function shouldReportNoDiagnostics(meta: StylableMeta, checkTransformDiagnostics?: boolean): void;
export declare type DiagnosticsBank = Record<string, (...args: any[]) => DiagnosticBase>;
export declare type UnwrapDiagnosticMessage<T extends DiagnosticsBank> = {
[K in keyof T]: (...args: Parameters<T[K]>) => string;
};
export declare function diagnosticBankReportToStrings<T extends DiagnosticsBank>(bank: T): UnwrapDiagnosticMessage<T>;
//# sourceMappingURL=diagnostics.d.ts.map

32

dist/diagnostics.js

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.shouldReportNoDiagnostics = exports.expectTransformDiagnostics = exports.expectAnalyzeDiagnostics = exports.findTestLocations = exports.matchDiagnostic = void 0;
exports.diagnosticBankReportToStrings = exports.shouldReportNoDiagnostics = exports.expectTransformDiagnostics = exports.expectAnalyzeDiagnostics = exports.findTestLocations = exports.matchDiagnostic = void 0;
const chai_1 = require("chai");

@@ -52,3 +52,3 @@ const deindent_1 = __importDefault(require("deindent"));

if (expected.location.word) {
if (report.options.word !== expected.location.word) {
if (report.word !== expected.location.word) {
matchState.word = errors.wordMismatch(type, expected.location.word, expected.message, expected.label);

@@ -61,4 +61,4 @@ foundPartialMatch(matchState);

if (expected.severity) {
if (report.type !== expectedSeverity) {
matchState.location = errors.severityMismatch(type, expectedSeverity, report.type, expected.message, expected.label);
if (report.severity !== expectedSeverity) {
matchState.location = errors.severityMismatch(type, expectedSeverity, report.severity, expected.message, expected.label);
foundPartialMatch(matchState);

@@ -118,3 +118,3 @@ continue;

const root = (0, index_internal_1.safeParse)(source.css);
const res = (0, index_internal_1.process)(root);
const res = new index_internal_1.StylableProcessor(new core_1.Diagnostics()).process(root);
if (partial) {

@@ -139,6 +139,6 @@ if (warnings.length === 0) {

if (source.word !== null) {
(0, chai_1.expect)(report.options.word).to.equal(source.word);
(0, chai_1.expect)(report.word).to.equal(source.word);
}
if (expectedWarning.severity) {
(0, chai_1.expect)(report.type, `diagnostics severity mismatch, expected "${expectedWarning.severity}" but received "${report.type}"`).to.equal(expectedWarning.severity);
(0, chai_1.expect)(report.severity, `diagnostics severity mismatch, expected "${expectedWarning.severity}" but received "${report.severity}"`).to.equal(expectedWarning.severity);
}

@@ -167,7 +167,7 @@ });

if (locations[path].word !== null) {
(0, chai_1.expect)(report.options.word).to.eql(locations[path].word);
(0, chai_1.expect)(report.word).to.eql(locations[path].word);
matches++;
}
if (expectedWarning.severity) {
(0, chai_1.expect)(report.type, `${report.message}: severity mismatch, expected ${expectedWarning.severity} but received ${report.type}`).to.equal(expectedWarning.severity);
(0, chai_1.expect)(report.severity, `${report.message}: severity mismatch, expected ${expectedWarning.severity} but received ${report.severity}`).to.equal(expectedWarning.severity);
matches++;

@@ -221,6 +221,6 @@ }

if (locations[path].word !== null) {
(0, chai_1.expect)(report.options.word).to.eql(locations[path].word);
(0, chai_1.expect)(report.word).to.eql(locations[path].word);
}
if (expectedWarning.severity) {
(0, chai_1.expect)(report.type, `diagnostics severity mismatch, expected ${expectedWarning.severity} but received ${report.type}`).to.equal(expectedWarning.severity);
(0, chai_1.expect)(report.severity, `diagnostics severity mismatch, expected ${expectedWarning.severity} but received ${report.severity}`).to.equal(expectedWarning.severity);
}

@@ -242,2 +242,12 @@ }

exports.shouldReportNoDiagnostics = shouldReportNoDiagnostics;
function diagnosticBankReportToStrings(bank) {
const cleaned = {};
for (const [diagName, diagFunc] of Object.entries(bank)) {
cleaned[diagName] = (...args) => {
return diagFunc(...args).message;
};
}
return cleaned;
}
exports.diagnosticBankReportToStrings = diagnosticBankReportToStrings;
//# sourceMappingURL=diagnostics.js.map

@@ -1,3 +0,3 @@

import { Diagnostics, FileProcessor, postProcessor, processNamespace, replaceValueHook, StylableMeta, StylableResolver, Stylable, StylableConfig } from '@stylable/core';
import { StylableTransformer } from '@stylable/core/dist/index-internal';
import { Diagnostics, processNamespace, StylableMeta, Stylable, StylableConfig } from '@stylable/core';
import { FileProcessor, StylableResolver, StylableTransformer, postProcessor, replaceValueHook } from '@stylable/core/dist/index-internal';
import * as postcss from 'postcss';

@@ -45,3 +45,3 @@ import type { IDirectoryContents } from '@file-services/types';

export declare function generateStylableRoot(config: Config): postcss.Root;
export declare function generateStylableExports(config: Config): import("@stylable/core").StylableExports;
export declare function generateStylableExports(config: Config): import("@stylable/core/dist/stylable-transformer").StylableExports;
export declare function generateStylableEnvironment(content: IDirectoryContents, stylableConfig?: Partial<StylableConfig>): {

@@ -48,0 +48,0 @@ stylable: Stylable;

@@ -41,3 +41,3 @@ "use strict";

const requireModule = (0, test_stylable_core_1.createJavascriptRequireModule)(fs);
const fileProcessor = (0, core_1.createStylableFileProcessor)({
const fileProcessor = (0, index_internal_1.createStylableFileProcessor)({
fileSystem: fs,

@@ -50,5 +50,5 @@ onProcess: (meta, filePath) => {

});
const resolveModule = (0, core_1.createDefaultResolver)(fs, {});
const resolveModule = (0, index_internal_1.createDefaultResolver)(fs, {});
const resolvePath = (context = '/', moduleId) => resolveModule(context, moduleId);
const resolver = new core_1.StylableResolver(fileProcessor, requireModule, resolvePath);
const resolver = new index_internal_1.StylableResolver(fileProcessor, requireModule, resolvePath);
return { resolver, requireModule, fileProcessor, resolvePath };

@@ -72,3 +72,3 @@ }

function processSource(source, options = {}, resolveNamespace) {
return (0, index_internal_1.process)(postcss.parse(source, options), undefined, resolveNamespace);
return new index_internal_1.StylableProcessor(new core_1.Diagnostics(), resolveNamespace).process(postcss.parse(source, options));
}

@@ -90,3 +90,3 @@ exports.processSource = processSource;

function generateStylableRoot(config) {
return generateStylableResult(config).meta.outputAst;
return generateStylableResult(config).meta.targetAst;
}

@@ -100,3 +100,3 @@ exports.generateStylableRoot = generateStylableRoot;

const fs = (0, memory_1.createMemoryFs)(content);
const stylable = core_1.Stylable.create({
const stylable = new core_1.Stylable({
fileSystem: fs,

@@ -103,0 +103,0 @@ projectRoot: '/',

@@ -1,2 +0,2 @@

export { Diagnostic, expectAnalyzeDiagnostics, expectTransformDiagnostics, findTestLocations, shouldReportNoDiagnostics, } from './diagnostics';
export { Diagnostic, expectAnalyzeDiagnostics, expectTransformDiagnostics, findTestLocations, shouldReportNoDiagnostics, diagnosticBankReportToStrings, } from './diagnostics';
export { Config, File, InfraConfig, RequireType, createProcess, createTransformer, generateInfra, generateStylableExports, generateStylableResult, generateStylableRoot, processSource, generateStylableEnvironment, } from './generate-test-util';

@@ -3,0 +3,0 @@ export { flatMatch } from './matchers/flat-match';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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;
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.diagnosticBankReportToStrings = exports.shouldReportNoDiagnostics = exports.findTestLocations = exports.expectTransformDiagnostics = exports.expectAnalyzeDiagnostics = void 0;
var diagnostics_1 = require("./diagnostics");

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

Object.defineProperty(exports, "shouldReportNoDiagnostics", { enumerable: true, get: function () { return diagnostics_1.shouldReportNoDiagnostics; } });
Object.defineProperty(exports, "diagnosticBankReportToStrings", { enumerable: true, get: function () { return diagnostics_1.diagnosticBankReportToStrings; } });
var generate_test_util_1 = require("./generate-test-util");

@@ -11,0 +12,0 @@ Object.defineProperty(exports, "createProcess", { enumerable: true, get: function () { return generate_test_util_1.createProcess; } });

import type { StylableMeta } from '@stylable/core';
import type * as postcss from 'postcss';
interface Context {
meta: Pick<StylableMeta, 'outputAst' | 'rawAst' | 'diagnostics' | 'transformDiagnostics'>;
meta: Pick<StylableMeta, 'sourceAst' | 'targetAst' | 'diagnostics' | 'transformDiagnostics'>;
}

@@ -6,0 +6,0 @@ /**

@@ -55,4 +55,4 @@ "use strict";

meta: {
outputAst: result,
rawAst: result,
sourceAst: result,
targetAst: result,
diagnostics: null,

@@ -63,3 +63,3 @@ transformDiagnostics: null,

: result;
const rootAst = context.meta.rawAst;
const rootAst = context.meta.sourceAst;
const expectedTestAmount = expectedTestInput !== null && expectedTestInput !== void 0 ? expectedTestInput : (((_a = rootAst.toString().match(new RegExp(`${testScopesRegex()}`, `gm`))) === null || _a === void 0 ? void 0 : _a.length) || 0);

@@ -342,6 +342,6 @@ const checks = [];

let match = undefined;
if (!meta.outputAst) {
if (!meta.targetAst) {
return;
}
meta.outputAst.walkComments((outputComment) => {
meta.targetAst.walkComments((outputComment) => {
var _a, _b, _c, _d, _e, _f;

@@ -348,0 +348,0 @@ if (((_b = (_a = outputComment.source) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.offset) === ((_c = source === null || source === void 0 ? void 0 : source.start) === null || _c === void 0 ? void 0 : _c.offset) &&

@@ -12,7 +12,7 @@ "use strict";

}
const { outputAst } = actual.meta;
if (!outputAst) {
throw new Error(`expected result to be transformed - missing outputAst on meta`);
const { targetAst } = actual.meta;
if (!targetAst) {
throw new Error(`expected result to be transformed - missing targetAst on meta`);
}
const nodes = outputAst.nodes;
const nodes = targetAst.nodes;
if (!nodes) {

@@ -38,8 +38,8 @@ throw new Error(`no rules found for media`);

if (!scopeRule) {
const { outputAst } = actual.meta;
if (!outputAst) {
throw new Error(`expected result to be transfromed - missing outputAst on meta`);
const { targetAst } = actual.meta;
if (!targetAst) {
throw new Error(`expected result to be transfromed - missing targetAst on meta`);
}
else {
scopeRule = outputAst;
scopeRule = targetAst;
}

@@ -46,0 +46,0 @@ }

@@ -20,3 +20,3 @@ "use strict";

(0, memory_1.createMemoryFs)(typeof input === `string` ? { '/entry.st.css': input } : input);
const stylable = core_1.Stylable.create({
const stylable = new core_1.Stylable({
fileSystem: fs,

@@ -44,3 +44,3 @@ projectRoot: '/',

const meta = stylable.analyze(path);
if (!meta.outputAst) {
if (!meta.targetAst) {
// ToDo: test

@@ -47,0 +47,0 @@ stylable.transform(meta);

{
"name": "@stylable/core-test-kit",
"version": "4.13.2",
"version": "5.0.0-rc.1",
"description": "Stylable core test-kit",

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

"@file-services/memory": "^6.0.0",
"@stylable/core": "^4.13.2",
"@stylable/core": "^v5.0.0-rc.1",
"chai": "^4.3.6",
"flat": "^5.0.2",
"postcss": "^8.4.13"
"postcss": "^8.4.14"
},

@@ -24,3 +24,3 @@ "files": [

"engines": {
"node": ">=12"
"node": ">=14.14.0"
},

@@ -27,0 +27,0 @@ "publishConfig": {

import { expect } from 'chai';
import deindent from 'deindent';
import type { Position } from 'postcss';
import { Diagnostics, DiagnosticType, StylableMeta, StylableResults } from '@stylable/core';
import { safeParse, process } from '@stylable/core/dist/index-internal';
import { Diagnostics, DiagnosticSeverity, StylableMeta, StylableResults } from '@stylable/core';
import { DiagnosticBase, safeParse, StylableProcessor } from '@stylable/core/dist/index-internal';
import { Config, generateStylableResult } from './generate-test-util';
export interface Diagnostic {
severity?: DiagnosticType;
severity?: DiagnosticSeverity;
message: string;

@@ -35,3 +35,4 @@ file: string;

});
const isSupportedSeverity = (val: string): val is DiagnosticType => !!val.match(/info|warn|error/);
const isSupportedSeverity = (val: string): val is DiagnosticSeverity =>
!!val.match(/info|warn|error/);
export function matchDiagnostic(

@@ -98,3 +99,3 @@ type: `analyze` | `transform`,

if (expected.location.word) {
if (report.options.word !== expected.location.word) {
if (report.word !== expected.location.word) {
matchState.word = errors.wordMismatch(

@@ -112,7 +113,7 @@ type,

if (expected.severity) {
if (report.type !== expectedSeverity) {
if (report.severity !== expectedSeverity) {
matchState.location = errors.severityMismatch(
type,
expectedSeverity,
report.type,
report.severity,
expected.message,

@@ -176,3 +177,3 @@ expected.label

const root = safeParse(source.css);
const res = process(root);
const res = new StylableProcessor(new Diagnostics()).process(root);

@@ -198,3 +199,3 @@ if (partial) {

if (source.word !== null) {
expect(report.options.word).to.equal(source.word);
expect(report.word).to.equal(source.word);
}

@@ -204,4 +205,4 @@

expect(
report.type,
`diagnostics severity mismatch, expected "${expectedWarning.severity}" but received "${report.type}"`
report.severity,
`diagnostics severity mismatch, expected "${expectedWarning.severity}" but received "${report.severity}"`
).to.equal(expectedWarning.severity);

@@ -238,3 +239,3 @@ }

if (locations[path].word !== null) {
expect(report.options.word).to.eql(locations[path].word);
expect(report.word).to.eql(locations[path].word);
matches++;

@@ -244,4 +245,4 @@ }

expect(
report.type,
`${report.message}: severity mismatch, expected ${expectedWarning.severity} but received ${report.type}`
report.severity,
`${report.message}: severity mismatch, expected ${expectedWarning.severity} but received ${report.severity}`
).to.equal(expectedWarning.severity);

@@ -308,3 +309,3 @@ matches++;

if (locations[path].word !== null) {
expect(report.options.word).to.eql(locations[path].word);
expect(report.word).to.eql(locations[path].word);
}

@@ -314,4 +315,4 @@

expect(
report.type,
`diagnostics severity mismatch, expected ${expectedWarning.severity} but received ${report.type}`
report.severity,
`diagnostics severity mismatch, expected ${expectedWarning.severity} but received ${report.severity}`
).to.equal(expectedWarning.severity);

@@ -349,1 +350,21 @@ }

}
export type DiagnosticsBank = Record<string, (...args: any[]) => DiagnosticBase>;
export type UnwrapDiagnosticMessage<T extends DiagnosticsBank> = {
[K in keyof T]: (...args: Parameters<T[K]>) => string;
};
export function diagnosticBankReportToStrings<T extends DiagnosticsBank>(
bank: T
): UnwrapDiagnosticMessage<T> {
const cleaned = {} as UnwrapDiagnosticMessage<T>;
for (const [diagName, diagFunc] of Object.entries(bank)) {
cleaned[diagName as keyof T] = (...args) => {
return diagFunc(...args).message;
};
}
return cleaned;
}
import {
Diagnostics,
FileProcessor,
postProcessor,
processNamespace,
replaceValueHook,
StylableMeta,
StylableResolver,
createStylableFileProcessor,
createDefaultResolver,
Stylable,

@@ -15,3 +9,12 @@ StylableConfig,

import { createJavascriptRequireModule } from './test-stylable-core';
import { process, StylableTransformer } from '@stylable/core/dist/index-internal';
import {
FileProcessor,
StylableProcessor,
StylableResolver,
StylableTransformer,
createStylableFileProcessor,
postProcessor,
replaceValueHook,
createDefaultResolver,
} from '@stylable/core/dist/index-internal';
import { isAbsolute } from 'path';

@@ -108,3 +111,5 @@ import * as postcss from 'postcss';

) {
return process(postcss.parse(source, options), undefined, resolveNamespace);
return new StylableProcessor(new Diagnostics(), resolveNamespace).process(
postcss.parse(source, options)
);
}

@@ -131,3 +136,3 @@

export function generateStylableRoot(config: Config) {
return generateStylableResult(config).meta.outputAst!;
return generateStylableResult(config).meta.targetAst!;
}

@@ -145,3 +150,3 @@

const stylable = Stylable.create({
const stylable = new Stylable({
fileSystem: fs,

@@ -148,0 +153,0 @@ projectRoot: '/',

@@ -7,2 +7,3 @@ export {

shouldReportNoDiagnostics,
diagnosticBankReportToStrings,
} from './diagnostics';

@@ -9,0 +10,0 @@ export {

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

interface Context {
meta: Pick<StylableMeta, 'outputAst' | 'rawAst' | 'diagnostics' | 'transformDiagnostics'>;
meta: Pick<StylableMeta, 'sourceAst' | 'targetAst' | 'diagnostics' | 'transformDiagnostics'>;
}

@@ -69,4 +69,4 @@ const isRoot = (val: any): val is postcss.Root => val.type === `root`;

meta: {
outputAst: result,
rawAst: result,
sourceAst: result,
targetAst: result,
diagnostics: null as unknown as StylableMeta['diagnostics'],

@@ -77,3 +77,3 @@ transformDiagnostics: null as unknown as StylableMeta['transformDiagnostics'],

: result;
const rootAst = context.meta.rawAst;
const rootAst = context.meta.sourceAst;
const expectedTestAmount =

@@ -433,6 +433,6 @@ expectedTestInput ??

let match: postcss.Comment | undefined = undefined;
if (!meta.outputAst) {
if (!meta.targetAst) {
return;
}
meta.outputAst.walkComments((outputComment) => {
meta.targetAst.walkComments((outputComment) => {
if (

@@ -439,0 +439,0 @@ outputComment.source?.start?.offset === source?.start?.offset &&

@@ -19,8 +19,8 @@ import type { StylableResults } from '@stylable/core';

const { outputAst } = actual.meta;
if (!outputAst) {
throw new Error(`expected result to be transformed - missing outputAst on meta`);
const { targetAst } = actual.meta;
if (!targetAst) {
throw new Error(`expected result to be transformed - missing targetAst on meta`);
}
const nodes = outputAst.nodes;
const nodes = targetAst.nodes;

@@ -58,9 +58,9 @@ if (!nodes) {

if (!scopeRule) {
const { outputAst } = actual.meta;
if (!outputAst) {
const { targetAst } = actual.meta;
if (!targetAst) {
throw new Error(
`expected result to be transfromed - missing outputAst on meta`
`expected result to be transfromed - missing targetAst on meta`
);
} else {
scopeRule = outputAst;
scopeRule = targetAst;
}

@@ -67,0 +67,0 @@ }

@@ -36,3 +36,3 @@ import { testInlineExpects } from './inline-expectation';

createMemoryFs(typeof input === `string` ? { '/entry.st.css': input } : input);
const stylable = Stylable.create({
const stylable = new Stylable({
fileSystem: fs,

@@ -63,3 +63,3 @@ projectRoot: '/',

const meta = stylable.analyze(path);
if (!meta.outputAst) {
if (!meta.targetAst) {
// ToDo: test

@@ -66,0 +66,0 @@ stylable.transform(meta);

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

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

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