mirror of
https://github.com/style-dictionary/style-dictionary.git
synced 2026-09-29 02:02:58 +08:00
88 lines
3.5 KiB
JavaScript
88 lines
3.5 KiB
JavaScript
/*
|
|
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
* the License. A copy of the License is located at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
* and limitations under the License.
|
|
*/
|
|
import { expect } from 'chai';
|
|
import childProcess from 'child_process';
|
|
import fs from 'node:fs';
|
|
import { clearOutput, fileExists } from '../__tests__/__helpers.js';
|
|
|
|
describe('cliBuildWithJsConfig', () => {
|
|
beforeEach(() => {
|
|
clearOutput(undefined, fs);
|
|
});
|
|
|
|
afterEach(() => {
|
|
clearOutput();
|
|
});
|
|
|
|
it('should work with json config', () => {
|
|
childProcess.execSync('node ./bin/style-dictionary build --config __tests__/__configs/test.js');
|
|
expect(fileExists('__tests__/__output/web/_icons.css', fs)).to.be.true;
|
|
expect(fileExists('__tests__/__output/android/colors.xml', fs)).to.be.true;
|
|
});
|
|
|
|
it('should work with javascript config', () => {
|
|
childProcess.execSync('node ./bin/style-dictionary build --config __tests__/__configs/test.js');
|
|
expect(fileExists('__tests__/__output/web/_icons.css', fs)).to.be.true;
|
|
expect(fileExists('__tests__/__output/android/colors.xml', fs)).to.be.true;
|
|
});
|
|
|
|
describe('logging args', () => {
|
|
it('should not log anything if --silent is used', () => {
|
|
const result = childProcess.execSync(
|
|
'node ./bin/style-dictionary build --config __tests__/__configs/test.js --silent',
|
|
);
|
|
expect(result.toString()).to.equal(``);
|
|
});
|
|
|
|
it('should only log success logs if --no-warn is used', () => {
|
|
const result = childProcess.execSync(
|
|
'node ./bin/style-dictionary build --config __tests__/__configs/test.js --no-warn',
|
|
);
|
|
|
|
expect(result.toString().match('Token collisions detected')).to.be.null;
|
|
});
|
|
|
|
it('should log briefly if neither --verbose nor --silent is used', () => {
|
|
//const logStub = stubMethod(console, 'log');
|
|
const result = childProcess.execSync(
|
|
'node ./bin/style-dictionary build --config __tests__/__configs/tokenCollisions.json',
|
|
);
|
|
expect(result.toString()).to.equal(`
|
|
css
|
|
⚠️ __tests__/__output/css/vars.css
|
|
While building vars.css, token collisions were found; output may be unexpected. Ignore this warning if intentional.
|
|
|
|
Use log.verbosity "verbose" or use CLI option --verbose for more details.
|
|
Refer to: https://styledictionary.com/reference/logging/\n`);
|
|
});
|
|
|
|
it('should log verbosely if --verbose is used', () => {
|
|
//const logStub = stubMethod(console, 'log');
|
|
const result = childProcess.execSync(
|
|
'node ./bin/style-dictionary build --config __tests__/__configs/tokenCollisions.json --verbose',
|
|
);
|
|
expect(result.toString()).to.equal(`
|
|
css
|
|
⚠️ __tests__/__output/css/vars.css
|
|
While building vars.css, token collisions were found; output may be unexpected. Ignore this warning if intentional.
|
|
Output name red was generated by:
|
|
color.red #f00
|
|
color.background.red #f00
|
|
This many-to-one issue is usually caused by some combination of:
|
|
* conflicting or similar paths/names in token definitions
|
|
* platform transforms/transformGroups affecting names, especially when removing specificity
|
|
* overly inclusive file filters\n`);
|
|
});
|
|
});
|
|
});
|