Integrate True with JavaScript test runners
mainYou can run Sass tests within JS frameworks like Mocha, Jest, or Vitest by using the sass-true package to bridge the two.
1. Create a JS test shim
Create a file (e.g., test/sass.test.js) to invoke the Sass compilation:
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import sassTrue from 'sass-true';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const sassFile = path.join(__dirname, 'test.scss');
// Pass your runner's describe/it functions to runSass
sassTrue.runSass({ describe, it }, sassFile);2. Configure Watch Mode
Standard JS runners may not detect .scss changes automatically.
- Vitest: Add Sass files to
forceRerunTriggersinvitest.config.js:test: { forceRerunTriggers: ['**/*.scss'] } - Jest: Add
scsstomoduleFileExtensionsinjest.config.js:moduleFileExtensions: ['js', 'json', 'scss']
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import sassTrue from 'sass-true';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const sassFile = path.join(__dirname, 'test.scss');
sassTrue.runSass({ describe, it }, sassFile);