From 4ccd14a434d5b3ec3ff14ce658c6099e54dee948 Mon Sep 17 00:00:00 2001 From: Jennifer Thakar Date: Tue, 21 May 2024 23:03:54 +0000 Subject: [PATCH] Disable deprecation type tests in the browser We don't have a good way to make the YAML file accessible to tests running in a browser, so we can just skip them there. --- js-api-spec/deprecations.node.test.ts | 65 +++++++++++++++++++++++++++ js-api-spec/deprecations.test.ts | 60 ------------------------- 2 files changed, 65 insertions(+), 60 deletions(-) create mode 100644 js-api-spec/deprecations.node.test.ts diff --git a/js-api-spec/deprecations.node.test.ts b/js-api-spec/deprecations.node.test.ts new file mode 100644 index 000000000..7f3cb92a2 --- /dev/null +++ b/js-api-spec/deprecations.node.test.ts @@ -0,0 +1,65 @@ +// Copyright 2024 Google LLC. Use of this source code is governed by an +// MIT-style license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +import fs from 'fs'; +import yaml from 'js-yaml'; +import {deprecations, Deprecation, Version} from 'sass'; + +describe('deprecation type', () => { + const deprecationsMap = deprecations as unknown as { + [key: string]: Deprecation; + }; + const obsoleteDeprecations: {[key: string]: [string, string]} = {}; + const activeDeprecations: {[key: string]: string} = {}; + const futureDeprecations: {[key: string]: true} = {}; + const data = yaml.load( + fs.readFileSync('js-api-spec/node_modules/sass/deprecations.yaml', 'utf8') + ) as { + [key: string]: { + 'dart-sass': + | {status: 'future'} + | {status: 'active'; deprecated: string} + | {status: 'obsolete'; deprecated: string; obsolete: string}; + }; + }; + for (const [id, deprecation] of Object.entries(data)) { + const dartSass = deprecation['dart-sass']; + if (dartSass.status === 'obsolete') { + obsoleteDeprecations[id] = [dartSass.deprecated, dartSass.obsolete]; + } else if (dartSass.status === 'active') { + activeDeprecations[id] = dartSass.deprecated; + } else if (dartSass.status === 'future') { + futureDeprecations[id] = true; + } + } + + for (const [id, versions] of Object.entries(obsoleteDeprecations)) { + if (!versions) continue; + const [deprecatedIn, obsoleteIn] = versions; + it(`${id} deprecated in ${deprecatedIn} and obsolete in ${obsoleteIn}`, () => { + const deprecation = deprecationsMap[id]; + expect(deprecation?.id).toBe(id); + expect(deprecation?.status).toBe('obsolete'); + expect(deprecation?.deprecatedIn).toEqual(Version.parse(deprecatedIn)); + expect(deprecation?.obsoleteIn).toEqual(Version.parse(obsoleteIn)); + }); + } + + for (const [id, version] of Object.entries(activeDeprecations)) { + it(`${id} deprecated in ${version}`, () => { + const deprecation = deprecationsMap[id]; + expect(deprecation?.id).toBe(id); + expect(deprecation?.status).toBe('active'); + expect(deprecation?.deprecatedIn).toEqual(Version.parse(version)); + }); + } + + for (const [id] of Object.entries(futureDeprecations)) { + it(`${id} is a future deprecation`, () => { + const deprecation = deprecationsMap[id]; + expect(deprecation?.id).toBe(id); + expect(deprecation?.status).toBe('future'); + }); + } +}); diff --git a/js-api-spec/deprecations.test.ts b/js-api-spec/deprecations.test.ts index 514b7214e..852c068f8 100644 --- a/js-api-spec/deprecations.test.ts +++ b/js-api-spec/deprecations.test.ts @@ -2,8 +2,6 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -import fs from 'fs'; -import yaml from 'js-yaml'; import { compileString, deprecations, @@ -14,64 +12,6 @@ import { import {captureStdio, URL} from './utils'; -describe('deprecation type', () => { - const deprecationsMap = deprecations as unknown as { - [key: string]: Deprecation; - }; - const obsoleteDeprecations: {[key: string]: [string, string]} = {}; - const activeDeprecations: {[key: string]: string} = {}; - const futureDeprecations: {[key: string]: true} = {}; - const data = yaml.load( - fs.readFileSync('js-api-spec/node_modules/sass/deprecations.yaml', 'utf8') - ) as { - [key: string]: { - 'dart-sass': - | {status: 'future'} - | {status: 'active'; deprecated: string} - | {status: 'obsolete'; deprecated: string; obsolete: string}; - }; - }; - for (const [id, deprecation] of Object.entries(data)) { - const dartSass = deprecation['dart-sass']; - if (dartSass.status === 'obsolete') { - obsoleteDeprecations[id] = [dartSass.deprecated, dartSass.obsolete]; - } else if (dartSass.status === 'active') { - activeDeprecations[id] = dartSass.deprecated; - } else if (dartSass.status === 'future') { - futureDeprecations[id] = true; - } - } - - for (const [id, versions] of Object.entries(obsoleteDeprecations)) { - if (!versions) continue; - const [deprecatedIn, obsoleteIn] = versions; - it(`${id} deprecated in ${deprecatedIn} and obsolete in ${obsoleteIn}`, () => { - const deprecation = deprecationsMap[id]; - expect(deprecation?.id).toBe(id); - expect(deprecation?.status).toBe('obsolete'); - expect(deprecation?.deprecatedIn).toEqual(Version.parse(deprecatedIn)); - expect(deprecation?.obsoleteIn).toEqual(Version.parse(obsoleteIn)); - }); - } - - for (const [id, version] of Object.entries(activeDeprecations)) { - it(`${id} deprecated in ${version}`, () => { - const deprecation = deprecationsMap[id]; - expect(deprecation?.id).toBe(id); - expect(deprecation?.status).toBe('active'); - expect(deprecation?.deprecatedIn).toEqual(Version.parse(version)); - }); - } - - for (const [id] of Object.entries(futureDeprecations)) { - it(`${id} is a future deprecation`, () => { - const deprecation = deprecationsMap[id]; - expect(deprecation?.id).toBe(id); - expect(deprecation?.status).toBe('future'); - }); - } -}); - describe('a warning', () => { it('is emitted with no flags', done => { compileString('a { $b: c !global; }', {