Skip to content

Commit

Permalink
chore(globals): update failing css--* tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack committed Mar 26, 2019
1 parent 1fdade4 commit 9edb556
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
21 changes: 16 additions & 5 deletions src/globals/scss/__tests__/css--font-face-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
* @jest-environment node
*/

const { renderSass } = require('../../../../tools/jest/scss');
const { createSassRenderer } = require('@carbon/test-utils/scss');

const render = createSassRenderer(__dirname);
const renderClassic = content =>
render(`
$feature-flags: (components-x: false, breaking-changes-x: false);
${content}
`);

describe('_css--font-face.scss', () => {
it('should not output CSS if $css--font-face is false', async () => {
const { result } = await renderSass(`
const { result } = await renderClassic(`
$css--reset: false;
$css--font-face: false;
@import './src/globals/scss/css--font-face';
`);
Expand All @@ -22,7 +30,8 @@ $css--font-face: false;
});

it('should output helvetica if $css--font-face is true and $css--plex is false', async () => {
const { result } = await renderSass(`
const { result } = await renderClassic(`
$css--reset: false;
$css--font-face: true;
$css--plex: false;
@import './src/globals/scss/css--font-face';
Expand All @@ -33,7 +42,8 @@ $css--plex: false;
});

it('should output plex if $css--font-face and $css--plex are true', async () => {
const { result } = await renderSass(`
const { result } = await renderClassic(`
$css--reset: false;
$css--font-face: true;
$css--plex: true;
@import './src/globals/scss/css--font-face';
Expand All @@ -45,7 +55,8 @@ $css--plex: true;

describe('experimental', () => {
it('should output @font-face blocks from elements if components-x flag is enabled', async () => {
const { result } = await renderSass(`
const { result } = await render(`
$css--reset: false;
$css--font-face: true;
$css--plex: true;
$feature-flags: (components-x: true);
Expand Down
35 changes: 23 additions & 12 deletions src/globals/scss/__tests__/css--plex-core-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
* @jest-environment node
*/

const { convert, renderSass } = require('../../../../tools/jest/scss');
const { convert, createSassRenderer } = require('@carbon/test-utils/scss');

const variables = ['font-path', 'unicodes', 'families', 'fallbacks', 'weights'];
const render = createSassRenderer(__dirname);
const renderClassic = content =>
render(`
$css--reset: false;
$feature-flags: (components-x: false, breaking-changes-x: false);
${content}
`);

describe('_css--plex-core', () => {
it.each(variables)('should export the variable $%s', async name => {
const { calls } = await renderSass(`
@import './src/globals/scss/css--plex-core';
const { calls } = await renderClassic(`
@import '../css--plex-core';
$c: test(global-variable-exists(${name}));
$value: test($${name});
Expand All @@ -26,33 +33,37 @@ $value: test($${name});

describe('check-default-font-path', () => {
it('should warn if the default $font-path uses unpkg', async () => {
const { output } = await renderSass(`
@import './src/globals/scss/css--plex-core';
const { output } = await renderClassic(`
@import '../css--plex-core';
@include check-default-font-path() {
$test: true;
};
`);
expect(output.warn).toHaveBeenCalledTimes(1);

// This should be called twice now that feature flags have diverged in v10
expect(output.warn).toHaveBeenCalledTimes(2);
});

it('should not warn if $font-path is set and does not contain unpkg', async () => {
const { output } = await renderSass(`
fit('should not warn if $font-path is set and does not contain unpkg', async () => {
const { output } = await renderClassic(`
$font-path: 'https://my-custom-cdn.com';
@import './src/globals/scss/css--plex-core';
@import '../css--plex-core';
@include check-default-font-path() {
$test: true;
};
`);
expect(output.warn).not.toHaveBeenCalled();
// This should be called only once becaues feature flags have diverged in
// v10
expect(output.warn).toHaveBeenCalledTimes(1);
});
});

describe('plex-font-face', () => {
it('should output @font-face files based on families, weights, and unicodes', async () => {
const { result } = await renderSass(`
@import './src/globals/scss/css--plex-core';
const { result } = await renderClassic(`
@import '../css--plex-core';
@include plex-font-face();
`);
Expand Down

0 comments on commit 9edb556

Please sign in to comment.