Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## UNRELEASED

- FEATURE: Validate `runSass` arguments and warn if using v6 API.
- DOCUMENTATION: Add note that `{ style: 'compressed' }` is not supported.
- DOCUMENTATION: Add note about possible Jest error and workaround.
- INTERNAL: Update dependencies
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export const runSass = function (
sassOpts.loadPaths = [sassPath];
}

// Warn if arguments match v6 API
if (typeof src !== 'string' || !trueOptions.describe || !trueOptions.it) {
throw new Error(
'The arguments provided to `runSass` do not match the new API introduced in True v7. Refer to the v7 release notes for migration documentation: https://github.com/oddbird/true/releases/tag/v7.0.0',
);
}

const compiler = trueOpts.sourceType === 'string' ? compileString : compile;
const parsedCss = compiler(src, sassOpts).css;
const modules = parse(parsedCss, trueOpts.contextLines);
Expand Down
25 changes: 25 additions & 0 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ describe('#fail', () => {
});

describe('#runSass', () => {
it('throws if arguments do not match newer API', () => {
const sass = [
'@use "true" as *;',
'@include test-module("Module") {',
' @include test("Test") {',
' @include assert("Assertion") {',
' @include output() {',
' height: 10px;',
' }',
' @include expect() {',
' height: 10px;',
' }',
' }',
' }',
'}',
].join('\n');
const mock = function (name, cb) {
cb();
};
const attempt = function () {
sassTrue.runSass({ data: sass }, { describe: mock, it: mock });
};
expect(attempt).to.throw('do not match the new API');
});

it('throws AssertionError on failure', () => {
const sass = [
'@use "true";',
Expand Down