Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): only run plugin for sass files #361

Merged
merged 1 commit into from
Jul 13, 2023
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
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { LegacyOptions } from 'sass/types/legacy/options';
* @returns `true` if the name of the file ends with a sass extension (.scss, .sass), case insensitive. `false`
* otherwise
*/
export function usePlugin(fileName: string) {
export function usePlugin(fileName: string): boolean {
if (typeof fileName === 'string') {
return /(\.scss|\.sass)$/i.test(fileName);
}
return true;
return false;
}

/**
Expand Down
21 changes: 7 additions & 14 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,20 @@ describe('getRenderOptions', () => {


describe('usePlugin', () => {

it('should use the plugin for .scss file', () => {
const fileName = 'my-file.scss';
expect(util.usePlugin(fileName)).toBe(true);
});

it('should use the plugin for .sass file', () => {
const fileName = 'my-file.sass';
it.each(['.sass', '.scss', '.SASS', '.SCSS'])('returns true for a %s file', (extension) => {
const fileName = `my-file${extension}`;
expect(util.usePlugin(fileName)).toBe(true);
});

it('should not use the plugin for .pcss file', () => {
const fileName = 'my-file.pcss';
it.each(['.pcss', '.css', '.ts', '.tsx', '.js', '.jsx', '.mjs'])('returns false for a %s file', (extension) => {
const fileName = `my-file${extension}`;
expect(util.usePlugin(fileName)).toBe(false);
});

it('should not use the plugin for .css file', () => {
const fileName = 'my-file.css';
expect(util.usePlugin(fileName)).toBe(false);
it.each([undefined, null])('returns false for non-string file (%s)', (fileName) => {
// the intent of this test is to intentionally provide a non-string value, hence the assertion
expect(util.usePlugin(fileName as unknown as string)).toBe(false);
});

});

describe('createResultsId', () => {
Expand Down