Skip to content

Commit

Permalink
Merge pull request #268 from oddbird/validate-args
Browse files Browse the repository at this point in the history
Warn if runSass args do not match newer API
  • Loading branch information
jgerigmeyer committed Jan 4, 2024
2 parents 8a671a9 + ec71c02 commit 9a86c4d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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

0 comments on commit 9a86c4d

Please sign in to comment.