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

sass-true

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sass-true - npm Package Compare versions

Comparing version 6.1.0 to 7.0.0-beta.0

72

CHANGELOG.md
# True Changelog
## 7.0.0-beta.0 (09/16/22)
- BREAKING: Upgrade to newer [Sass API](https://sass-lang.com/documentation/js-api)
- Add True `sourceType` option (`path` [default] or `string`)
- Reverse order of expected arguments to `runSass`: 1) True options, 2) source
path (or string), 3) optional Sass options
- BREAKING: Require `sass` as a peer-dependency, removing True `sass` option
- BREAKING: Drop support for node < 14.15.0
- INTERNAL: Use both Jest and Mocha for internal testing
- INTERNAL: Update dependencies
### Migrating from v6
- `runSass` arguments have changed:
v6:
```js
const path = require('path');
const sass = require('node-sass');
const sassTrue = require('sass-true');
const sassFile = path.join(__dirname, 'test.scss');
sassTrue.runSass(
// Sass options [required]
{ file: sassFile, outputStyle: 'compressed' },
// True options [required]
{ describe, it, sass },
);
const sassString = `
h1 {
font-size: 40px;
}`;
sassTrue.runSass(
// Sass options [required]
{ data: sassString, outputStyle: 'compressed' },
// True options [required]
{ describe, it, sass },
);
```
v7:
```js
const path = require('path');
const sassTrue = require('sass-true');
const sassFile = path.join(__dirname, 'test.scss');
sassTrue.runSass(
// True options [required]
{ describe, it },
// Sass source (path) [required]
sassFile,
// Sass options [optional]
{ style: 'compressed' },
);
const sassString = `
h1 {
font-size: 40px;
}`;
sassTrue.runSass(
// True options [required]
{ describe, it, sourceType: 'string' },
// Sass source (string) [required]
sassString,
// Sass options [optional]
{ style: 'compressed' },
);
```
## 6.1.0 (03/02/22)

@@ -4,0 +76,0 @@

7

lib/index.d.ts
import * as css from 'css';
import type { Options, StringOptions } from 'sass';
export interface TrueOptions {
describe: (description: string, fn: () => void) => void;
it: (description: string, fn: () => void) => void;
sass?: any;
sourceType?: 'path' | 'string';
contextLines?: number;

@@ -36,4 +37,4 @@ }

export declare type Parser = (rule: Rule, ctx: Context) => Parser;
export declare const runSass: (sassOptions: any, trueOptions: TrueOptions) => void;
export declare const runSass: (trueOptions: TrueOptions, src: string, sassOptions?: Options<'sync'> | StringOptions<'sync'>) => void;
export declare const formatFailureMessage: (assertion: Assertion) => string;
export declare const parse: (rawCss: Readonly<string>, ctxLines?: number | undefined) => Module[];
export declare const parse: (rawCss: Readonly<string>, ctxLines?: Readonly<number>) => Module[];

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

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -31,28 +35,17 @@ if (k2 === undefined) k2 = k;

const path = __importStar(require("path"));
const sass_1 = require("sass");
const constants = __importStar(require("./constants"));
const utils_1 = require("./utils");
const runSass = function (sassOptions, trueOptions) {
const runSass = function (trueOptions, src, sassOptions) {
const trueOpts = Object.assign({}, trueOptions);
const sassOpts = Object.assign({}, sassOptions);
const trueOpts = Object.assign({}, trueOptions);
const sassPath = path.join(__dirname, '..', 'sass');
if (sassOpts.includePaths) {
sassOpts.includePaths.push(sassPath);
if (sassOpts.loadPaths) {
sassOpts.loadPaths.push(sassPath);
}
else {
sassOpts.includePaths = [sassPath];
sassOpts.loadPaths = [sassPath];
}
let sass;
if (trueOpts.sass) {
sass = trueOpts.sass;
}
else {
// eslint-disable-next-line global-require
sass = require('sass');
}
/* istanbul ignore if */
if (!sass) {
throw new Error('No Sass implementation found.');
}
// eslint-disable-next-line no-sync
const parsedCss = sass.renderSync(sassOpts).css.toString();
const compiler = trueOpts.sourceType === 'string' ? sass_1.compileString : sass_1.compile;
const parsedCss = compiler(src, sassOpts).css;
const modules = (0, exports.parse)(parsedCss, trueOpts.contextLines);

@@ -59,0 +52,0 @@ (0, lodash_1.forEach)(modules, (module) => {

{
"name": "sass-true",
"title": "True",
"version": "6.1.0",
"version": "7.0.0-beta.0",
"description": "Unit testing for Sass.",

@@ -44,7 +44,7 @@ "keywords": [

"engines": {
"node": ">=10"
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
},
"scripts": {
"test:src": "jest",
"test:lib": "USE_BUILT=true jest --coverage=false",
"test:lib": "USE_BUILT=true mocha",
"test": "run-s build:js test:src test:lib",

@@ -68,35 +68,40 @@ "prettier:js": "prettier --write '**/*.js'",

},
"peerDependencies": {
"sass": ">=1.45.0"
},
"dependencies": {
"@types/css": "^0.0.33",
"css": "^3.0.0",
"jest-diff": "^27.5.1",
"jest-diff": "^29.0.3",
"lodash": "^4.17.21"
},
"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@types/lodash": "^4.14.178",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"babel-jest": "^27.5.1",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.4.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"jest": "^27.5.1",
"@babel/core": "^7.19.1",
"@babel/preset-env": "^7.19.1",
"@babel/preset-typescript": "^7.18.6",
"@types/lodash": "^4.14.185",
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"babel-jest": "^29.0.3",
"chai": "^4.3.6",
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-simple-import-sort": "^8.0.0",
"jest": "^29.0.3",
"jest-environment-node-single-context": "^29.0.0",
"mocha": "^10.0.0",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.6",
"prettier": "^2.5.1",
"sass": "^1.49.8",
"sassdoc": "^2.7.3",
"postcss": "^8.4.16",
"prettier": "^2.7.1",
"sass": "^1.54.9",
"sassdoc": "^2.7.4",
"sassdoc-theme-herman": "^4.0.2",
"stylelint": "^14.5.3",
"stylelint": "^14.11.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-standard-scss": "^3.0.0",
"stylelint-config-standard-scss": "^5.0.0",
"stylelint-prettier": "^2.0.0",
"typescript": "^4.5.5"
"typescript": "^4.8.3"
},

@@ -103,0 +108,0 @@ "eyeglass": {

@@ -26,12 +26,2 @@ # True

_Note that **Node Sass**
is several years behind **Dart Sass**
and the official Sass specification.
It will soon be
[deprecated entirely](https://github.com/sass/node-sass/issues/2952),
so we've decided to move forward
with the latest Sass features,
and **no longer support Node Sass
in any new (6.0+) releases**._
## Install

@@ -42,3 +32,3 @@

```bash
npm install sass-true
npm install --save-dev sass-true
```

@@ -148,4 +138,3 @@

See the [full documentation online](https://www.oddbird.net/true/)
or in the `.sassdoc` directory,
See the [full documentation online](https://www.oddbird.net/true/docs/)
for more details.

@@ -178,3 +167,3 @@ See [CHANGELOG.md](https://github.com/oddbird/true/blob/main/CHANGELOG.md)

const sassFile = path.join(__dirname, 'test.scss');
sassTrue.runSass({ file: sassFile }, { describe, it });
sassTrue.runSass({ describe, it }, sassFile);
```

@@ -184,10 +173,2 @@

~~**Note:** Jest defaults to running tests in a browser-like environment
(jsdom). When using with True, set the
[testEnvironment](https://jestjs.io/docs/26.x/configuration#testenvironment-string)
to "node".~~
**Update:** Since Jest v27, `testEnvironment` defaults to "node" and no changes
are needed.
**Note:** Jest does not watch for changes in Sass files by default. To use

@@ -201,14 +182,8 @@ `jest --watch` with True, add "scss" to your

The first argument to `runSass` accepts the
[same options](https://sass-lang.com/documentation/js-api/interfaces/LegacySharedOptions)
that sass' `renderSync` function accepts. The only modification `runSass` makes
is to add True's sass path to the `includePaths` option, so `@use 'true';` works
in your Sass test file.
The first argument is an object with required `describe` and `it` options, and
optional `contextLines` and `sourceType` options.
The second argument is an object with required `describe` and `it` options, and
optional `contextLines` and `sass` options.
Any JS test runner with equivalents to Mocha's or Jest's `describe` and `it`
should be usable in the same way: just pass your test runner's `describe` and
`it` equivalents in the second argument to `runSass`.
`it` equivalents in the first argument to `runSass`.

@@ -221,25 +196,44 @@ If True can't parse the CSS output, it'll give you some context lines of CSS as

You can also provide a `sass` option to provide a different Sass implementation.
This option expects an implementation providing a `renderSync` method with the
[same signature](https://sass-lang.com/documentation/js-api/modules#renderSync) as Dart
Sass, and support for the
[Sass module system](https://sass-lang.com/blog/the-module-system-is-launched).
The second argument is a string representing either the path to a source Sass
file (passed through to Sass'
[`compile`](https://sass-lang.com/documentation/js-api/modules#compile)
function), or a string of source Sass (passed through to Sass'
[`compileString`](https://sass-lang.com/documentation/js-api/modules#compileString)
function). By default it is expected to be a path, and `sass.compile` is used --
to pass in a source string (and use `sass.compileString`), add `sourceType: 'string'` to your options passed in as the first argument to `runSass`.
### Imports without Webpack
The third (optional) argument to `runSass` accepts the [same
options](https://sass-lang.com/documentation/js-api/interfaces/Options) that
Sass' `compile` or `compileString` expect, and these are passed directly through
to Sass. The only modification `runSass` makes is to add True's sass path to the
`loadPaths` option, so `@use 'true';` works in your Sass test file.
### Custom Importers
If you use Webpack's tilde notation, like `@use '~accoutrement/sass/tools'`,
you'll need to tell `runSass` how to handle that. That will require writing a
custom importer and passing it into the configuration for `runSass`. Something
like:
[custom importer](https://sass-lang.com/documentation/js-api/interfaces/FileImporter)
and passing it into the configuration for `runSass`:
```js
function importer(url, prev, done) {
if (url[0] === '~') {
url = path.resolve('node_modules', url.substr(1));
}
const path = require('path');
const { pathToFileURL } = require('url');
return { file: url };
}
const sassTrue = require('sass-true');
sassTrue.runSass({ importer, file: sassFile }, { describe, it });
const importers = [
{
findFileUrl(url) {
if (!url.startsWith('~')) {
return null;
}
return new URL(
pathToFileURL(path.resolve('node_modules', url.substring(1))),
);
},
},
];
const sassFile = path.join(__dirname, 'test.scss');
sassTrue.runSass({ describe, it }, sassFile, { importers });
```

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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