diff --git a/js-api-spec/deprecations.node.test.ts b/js-api-spec/deprecations.node.test.ts index b0e649f49..a1df09e33 100644 --- a/js-api-spec/deprecations.node.test.ts +++ b/js-api-spec/deprecations.node.test.ts @@ -4,7 +4,29 @@ import fs from 'fs'; import yaml from 'js-yaml'; -import {deprecations, Deprecation, Version} from 'sass'; +import {deprecations, renderSync, Deprecation, Version} from 'sass'; +import {captureStdio} from './utils'; + +describe('a warning from the JS API', () => { + it('is emitted with no flags', () => { + const stdio = captureStdio(() => { + renderSync({ + data: 'a { b: c; }', + }); + }); + expect(stdio.err).toContain('legacy-js-api'); + }); + + it('is not emitted when deprecation silenced', () => { + const stdio = captureStdio(() => { + renderSync({ + data: 'a { b: c; }', + silenceDeprecations: [deprecations['legacy-js-api']], + }); + }); + expect(stdio.err).toBe(''); + }); +}); describe('deprecation type', () => { const deprecationsMap = deprecations as unknown as { diff --git a/js-api-spec/deprecations.test.ts b/js-api-spec/deprecations.test.ts index b50222e74..d7909e3b6 100644 --- a/js-api-spec/deprecations.test.ts +++ b/js-api-spec/deprecations.test.ts @@ -7,7 +7,10 @@ import { deprecations, Deprecation, Importer, + Value, Version, + SassColor, + SassNumber, } from 'sass'; import {captureStdio, URL} from './utils'; @@ -226,3 +229,49 @@ describe('for a future deprecation,', () => { }); }); }); + +describe('color deprecations', () => { + it('emit a warning outside of any compilation', () => { + const stdio = captureStdio(() => { + new SassColor({red: 255, green: 0, blue: 0, space: 'rgb'}).red; + }); + expect(stdio.err).toContain('color-4-api'); + }); + + it('emit a warning when compilation not silenced', () => { + const stdio = captureStdio(() => { + compileString('a { b: fn(red); }', { + functions: { + 'fn($color)': (args: Value[]) => + new SassNumber(args[0].assertColor().red), + }, + }); + }); + expect(stdio.err).toContain('color-4-api'); + }); + + it('emit no warning when silenced in current compilation', () => { + const stdio = captureStdio(() => { + compileString('a { b: fn(red); }', { + silenceDeprecations: ['color-4-api'], + functions: { + 'fn($color)': (args: Value[]) => + new SassNumber(args[0].assertColor().red), + }, + }); + }); + expect(stdio.err).toEqual(''); + }); + + it('throw an error when made fatal in current compilation', () => { + expect(() => + compileString('a { b: fn(red); }', { + fatalDeprecations: ['color-4-api'], + functions: { + 'fn($color)': (args: Value[]) => + new SassNumber(args[0].assertColor().red), + }, + }) + ).toThrowError(); + }); +}); diff --git a/js-api-spec/legacy/render.node.test.ts b/js-api-spec/legacy/render.node.test.ts index ccff0a1cc..461b98025 100644 --- a/js-api-spec/legacy/render.node.test.ts +++ b/js-api-spec/legacy/render.node.test.ts @@ -505,6 +505,7 @@ describe('options', () => { file: dir('test.scss'), quietDeps: true, includePaths: [dir('dir')], + silenceDeprecations: ['legacy-js-api'], }) ); expect(stdio.out).toBeEmptyString(); @@ -523,6 +524,7 @@ describe('options', () => { file: dir('test.scss'), quietDeps: true, includePaths: [dir('dir')], + silenceDeprecations: ['legacy-js-api'], }) ); expect(stdio.out).toBeEmptyString(); @@ -566,6 +568,7 @@ describe('options', () => { file: dir('test.scss'), // data: '@import "other"', futureDeprecations: ['import'], + silenceDeprecations: ['legacy-js-api'], }) ); expect(stdio.out).toBeEmptyString(); @@ -583,6 +586,7 @@ describe('options', () => { const stdio = captureStdio(() => sass.renderSync({ file: dir('test.scss'), + silenceDeprecations: ['legacy-js-api'], }) ); expect(stdio.out).toBeEmptyString(); @@ -596,7 +600,7 @@ describe('options', () => { const stdio = captureStdio(() => sass.renderSync({ data: '$_: 1/2;', - silenceDeprecations: ['slash-div'], + silenceDeprecations: ['slash-div', 'legacy-js-api'], }) ); expect(stdio.out).toBeEmptyString(); @@ -691,6 +695,7 @@ describe('options', () => { expect(message).toBe('heck debug'); }, }, + silenceDeprecations: ['legacy-js-api'], }, (err?: sass.LegacyException, result?: sass.LegacyResult) => { if (err) {