How to use findConfig method in storybook-root

Best JavaScript code snippet using storybook-root

options.spec.js

Source:options.spec.js Github

copy

Full Screen

1'use strict';2const sinon = require('sinon');3const rewiremock = require('rewiremock/node');4const {ONE_AND_DONE_ARGS} = require('../../../lib/cli/one-and-dones');5const modulePath = require.resolve('../../../lib/cli/options');6const mocharcPath = require.resolve('../../../lib/mocharc.json');7const configPath = require.resolve('../../../lib/cli/config');8const proxyLoadOptions = ({9 readFileSync = {},10 findupSync = null,11 findConfig = {},12 loadConfig = {}13} = {}) =>14 rewiremock.proxy(modulePath, r => ({15 fs: r.with({readFileSync}).directChildOnly(),16 [mocharcPath]: defaults,17 'find-up': r18 .by(() => (findupSync ? {sync: findupSync} : {}))19 .directChildOnly(),20 [configPath]: r.with({findConfig, loadConfig}).directChildOnly()21 })).loadOptions;22const defaults = {23 timeout: 1000,24 extension: ['js']25};26describe('options', function() {27 let readFileSync;28 let findupSync;29 let loadOptions;30 let findConfig;31 let loadConfig;32 afterEach(function() {33 sinon.restore();34 });35 /**36 * Order of priority:37 * 1. Command-line args38 * 2. RC file (`.mocharc.js`, `.mocharc.ya?ml`, `mocharc.json`)39 * 3. `mocha` prop of `package.json`40 * 4. default rc41 */42 describe('loadOptions()', function() {43 describe('when no parameter provided', function() {44 beforeEach(function() {45 this.timeout(1000);46 readFileSync = sinon.stub();47 readFileSync.onFirstCall().returns('{}');48 findConfig = sinon.stub().returns('/some/.mocharc.json');49 loadConfig = sinon.stub().returns({});50 findupSync = sinon.stub().returns('/some/package.json');51 loadOptions = proxyLoadOptions({52 readFileSync,53 findConfig,54 loadConfig,55 findupSync56 });57 });58 it('should return an object containing positional args, defaults, and anti-reloading flags', function() {59 expect(60 loadOptions(),61 'to equal',62 Object.assign({}, defaults, {63 _: [],64 config: false,65 package: false66 })67 );68 });69 });70 describe('when parameter provided', function() {71 describe('package.json', function() {72 describe('when path to package.json (`--package <path>`) is valid', function() {73 let result;74 beforeEach(function() {75 const filepath = '/some/package.json';76 readFileSync = sinon.stub();77 // package.json78 readFileSync.onFirstCall().returns('{"mocha": {"retries": 3}}');79 findConfig = sinon.stub().returns('/some/.mocharc.json');80 loadConfig = sinon.stub().returns({});81 findupSync = sinon.stub();82 loadOptions = proxyLoadOptions({83 readFileSync,84 findConfig,85 loadConfig,86 findupSync87 });88 result = loadOptions(['--package', filepath]);89 });90 it('should return merged options incl. package.json opts', function() {91 expect(92 result,93 'to equal',94 Object.assign(95 {96 _: []97 },98 defaults,99 {100 config: false,101 package: false,102 retries: 3103 }104 )105 );106 });107 it('should not try to find a package.json', function() {108 expect(findupSync, 'was not called');109 });110 it('should set package = false', function() {111 expect(result, 'to have property', 'package', false);112 });113 });114 describe('when path to package.json (`--package <path>`) is invalid', function() {115 beforeEach(function() {116 readFileSync = sinon.stub();117 // package.json118 readFileSync.onFirstCall().throws('yikes');119 findConfig = sinon.stub().returns('/some/.mocharc.json');120 loadConfig = sinon.stub().returns({});121 findupSync = sinon.stub();122 loadOptions = proxyLoadOptions({123 readFileSync,124 findConfig,125 loadConfig,126 findupSync127 });128 });129 it('should throw', function() {130 expect(131 () => {132 loadOptions('--package /something/wherever --require butts');133 },134 'to throw',135 /unable to read\/parse/i136 );137 });138 });139 describe('when path to package.json unspecified', function() {140 let result;141 beforeEach(function() {142 const filepath = '/some/package.json';143 readFileSync = sinon.stub();144 // package.json145 readFileSync146 .onFirstCall()147 .returns('{"mocha": {"retries": 3, "_": ["foobar.spec.js"]}}');148 findConfig = sinon.stub().returns('/some/.mocharc.json');149 loadConfig = sinon.stub().returns({});150 findupSync = sinon.stub().returns(filepath);151 loadOptions = proxyLoadOptions({152 readFileSync,153 findConfig,154 loadConfig,155 findupSync156 });157 result = loadOptions();158 });159 it('should return merged options incl. found package.json', function() {160 expect(161 result,162 'to equal',163 Object.assign(164 {165 _: ['foobar.spec.js']166 },167 defaults,168 {169 config: false,170 package: false,171 retries: 3172 }173 )174 );175 });176 it('should set package = false', function() {177 expect(result, 'to have property', 'package', false);178 });179 });180 describe('when called with package = false (`--no-package`)', function() {181 let result;182 beforeEach(function() {183 readFileSync = sinon.stub();184 readFileSync.onFirstCall().returns('{}');185 findConfig = sinon.stub().returns('/some/path/to/.mocharc.json');186 loadConfig = sinon.stub().returns({'check-leaks': true});187 findupSync = sinon.stub().returns('/some/package.json');188 loadOptions = proxyLoadOptions({189 readFileSync,190 findConfig,191 loadConfig,192 findupSync193 });194 result = loadOptions('--no-diff --no-package');195 });196 it('should return parsed args and default config', function() {197 expect(198 result,199 'to equal',200 Object.assign({_: []}, defaults, {201 diff: false,202 'check-leaks': true,203 config: false,204 package: false205 })206 );207 });208 it('should not look for package.json', function() {209 expect(findupSync, 'was not called');210 });211 it('should set package = false', function() {212 expect(result, 'to have property', 'package', false);213 });214 });215 });216 describe('rc file', function() {217 describe('when called with config = false (`--no-config`)', function() {218 let result;219 beforeEach(function() {220 readFileSync = sinon.stub();221 readFileSync222 .onFirstCall()223 .returns(224 '{"mocha": {"check-leaks": true, "_": ["foobar.spec.js"]}}'225 );226 findConfig = sinon.stub();227 loadConfig = sinon.stub();228 findupSync = sinon.stub().returns('/some/package.json');229 loadOptions = proxyLoadOptions({230 readFileSync,231 findConfig,232 loadConfig,233 findupSync234 });235 result = loadOptions('--no-diff --no-config');236 });237 it('should return parsed args, default config and package.json', function() {238 expect(239 result,240 'to equal',241 Object.assign({_: ['foobar.spec.js']}, defaults, {242 diff: false,243 'check-leaks': true,244 config: false,245 package: false246 })247 );248 });249 it('should not attempt to load a config file', function() {250 expect(loadConfig, 'was not called');251 });252 it('should not attempt to find a config file', function() {253 expect(findConfig, 'was not called');254 });255 it('should set config = false', function() {256 expect(loadOptions(), 'to have property', 'config', false);257 });258 });259 describe('when path to config (`--config <path>`) is invalid', function() {260 let config;261 beforeEach(function() {262 readFileSync = sinon.stub();263 config = '/some/.mocharc.json';264 readFileSync.onFirstCall().returns('{}');265 findConfig = sinon.stub();266 loadConfig = sinon.stub().throws('Error', 'failed to parse');267 findupSync = sinon.stub().returns('/some/package.json');268 loadOptions = proxyLoadOptions({269 readFileSync,270 findConfig,271 loadConfig,272 findupSync273 });274 });275 it('should not look for a config', function() {276 try {277 loadOptions(`--config ${config}`);278 } catch (ignored) {}279 expect(findConfig, 'was not called');280 });281 it('should attempt to load file at path', function() {282 try {283 loadOptions(`--config ${config}`);284 } catch (ignored) {}285 expect(loadConfig, 'to have a call satisfying', [config]);286 });287 it('should throw to warn the user', function() {288 expect(289 () => {290 loadOptions(`--config ${config}`);291 },292 'to throw',293 'failed to parse'294 );295 });296 });297 describe('when called with unspecified config', function() {298 describe('when an rc file would be found', function() {299 let result;300 beforeEach(function() {301 readFileSync = sinon.stub();302 readFileSync.onFirstCall().returns('{}');303 readFileSync.onSecondCall().throws();304 findConfig = sinon.stub().returns('/some/.mocharc.json');305 loadConfig = sinon.stub().returns({});306 findupSync = sinon.stub().returns('/some/package.json');307 loadOptions = proxyLoadOptions({308 readFileSync,309 findConfig,310 loadConfig,311 findupSync312 });313 result = loadOptions();314 });315 it('should look for a config', function() {316 expect(findConfig, 'was called');317 });318 it('should attempt to load file at found path', function() {319 expect(loadConfig, 'to have a call satisfying', [320 '/some/.mocharc.json'321 ]);322 });323 it('should set config = false', function() {324 expect(result, 'to have property', 'config', false);325 });326 });327 describe('when an rc file would not be found', function() {328 let result;329 beforeEach(function() {330 readFileSync = sinon.stub();331 readFileSync.onFirstCall().returns('{}');332 readFileSync.onSecondCall().throws();333 findConfig = sinon.stub().returns(null);334 loadConfig = sinon.stub().returns({});335 findupSync = sinon.stub().returns('/some/package.json');336 loadOptions = proxyLoadOptions({337 readFileSync,338 findConfig,339 loadConfig,340 findupSync341 });342 result = loadOptions();343 });344 it('should look for a config', function() {345 expect(findConfig, 'was called');346 });347 it('should not attempt to load a config file', function() {348 expect(loadConfig, 'was not called');349 });350 it('should set config = false', function() {351 expect(result, 'to have property', 'config', false);352 });353 });354 });355 });356 });357 describe('config priority', function() {358 it('should prioritize package.json over defaults', function() {359 readFileSync = sinon.stub();360 readFileSync361 .onFirstCall()362 .returns(363 '{"mocha": {"timeout": 700, "require": "bar", "extension": "ts"}}'364 );365 findConfig = sinon.stub().returns('/some/.mocharc.json');366 loadConfig = sinon.stub().returns({});367 findupSync = sinon.stub().returns('/some/package.json');368 loadOptions = proxyLoadOptions({369 readFileSync,370 findConfig,371 loadConfig,372 findupSync373 });374 expect(loadOptions(), 'to satisfy', {375 timeout: 700,376 require: ['bar'],377 extension: ['ts']378 });379 });380 it('should prioritize rc file over package.json', function() {381 readFileSync = sinon.stub();382 readFileSync.onFirstCall().returns('{"mocha": {"timeout": 700}}');383 readFileSync.onSecondCall().returns('--timeout 800');384 findConfig = sinon.stub().returns('/some/.mocharc.json');385 loadConfig = sinon.stub().returns({timeout: 600});386 findupSync = sinon.stub().returns('/some/package.json');387 loadOptions = proxyLoadOptions({388 readFileSync,389 findConfig,390 loadConfig,391 findupSync392 });393 expect(loadOptions(), 'to have property', 'timeout', 600);394 });395 it('should prioritize args over rc file', function() {396 readFileSync = sinon.stub();397 readFileSync.onFirstCall().returns('{"mocha": {"timeout": 700}}');398 readFileSync.onSecondCall().returns('--timeout 800');399 findConfig = sinon.stub().returns('/some/.mocharc.json');400 loadConfig = sinon.stub().returns({timeout: 600});401 findupSync = sinon.stub().returns('/some/package.json');402 loadOptions = proxyLoadOptions({403 readFileSync,404 findConfig,405 loadConfig,406 findupSync407 });408 expect(409 loadOptions('--timeout 500'),410 'to have property',411 'timeout',412 '500'413 );414 });415 });416 describe('when called with a one-and-done arg', function() {417 beforeEach(function() {418 readFileSync = sinon.stub();419 findConfig = sinon.stub();420 loadConfig = sinon.stub();421 findupSync = sinon.stub();422 loadOptions = proxyLoadOptions({423 readFileSync,424 findConfig,425 loadConfig,426 findupSync427 });428 });429 ONE_AND_DONE_ARGS.forEach(arg => {430 describe(`"${arg}"`, function() {431 it(`should return basic parsed arguments and flag`, function() {432 expect(loadOptions(`--${arg}`), 'to equal', {_: [], [arg]: true});433 });434 });435 });436 });437 describe('"extension" handling', function() {438 describe('when user supplies "extension" option', function() {439 let result;440 beforeEach(function() {441 readFileSync = sinon.stub();442 readFileSync.onFirstCall().throws();443 findConfig = sinon.stub().returns('/some/.mocharc.json');444 loadConfig = sinon.stub().returns({extension: ['tsx']});445 findupSync = sinon.stub();446 loadOptions = proxyLoadOptions({447 readFileSync,448 findConfig,449 loadConfig,450 findupSync451 });452 result = loadOptions(['--extension', 'ts']);453 });454 it('should not concatenate the default value', function() {455 expect(result, 'to have property', 'extension', ['ts', 'tsx']);456 });457 });458 describe('when user does not supply "extension" option', function() {459 let result;460 beforeEach(function() {461 readFileSync = sinon.stub();462 readFileSync.onFirstCall().throws();463 findConfig = sinon.stub().returns('/some/.mocharc.json');464 loadConfig = sinon.stub().returns({});465 findupSync = sinon.stub();466 loadOptions = proxyLoadOptions({467 readFileSync,468 findConfig,469 loadConfig,470 findupSync471 });472 result = loadOptions();473 });474 it('should retain the default', function() {475 expect(result, 'to have property', 'extension', ['js']);476 });477 });478 });479 describe('"spec" handling', function() {480 describe('when user supplies "spec" in config and positional arguments', function() {481 let result;482 beforeEach(function() {483 readFileSync = sinon.stub();484 readFileSync.onFirstCall().throws();485 findConfig = sinon.stub().returns('/some/.mocharc.json');486 loadConfig = sinon.stub().returns({spec: '{dirA,dirB}/**/*.spec.js'});487 findupSync = sinon.stub();488 loadOptions = proxyLoadOptions({489 readFileSync,490 findConfig,491 loadConfig,492 findupSync493 });494 result = loadOptions(['*.test.js']);495 });496 it('should place both - unsplitted - into the positional arguments array', function() {497 expect(result, 'to have property', '_', [498 '*.test.js',499 '{dirA,dirB}/**/*.spec.js'500 ]);501 });502 });503 });504 describe('"ignore" handling', function() {505 let result;506 beforeEach(function() {507 readFileSync = sinon.stub();508 readFileSync.onFirstCall().throws();509 findConfig = sinon.stub().returns('/some/.mocharc.json');510 loadConfig = sinon.stub().returns({ignore: '{dirA,dirB}/**/*.spec.js'});511 findupSync = sinon.stub();512 loadOptions = proxyLoadOptions({513 readFileSync,514 findConfig,515 loadConfig,516 findupSync517 });518 result = loadOptions(['--ignore', '*.test.js']);519 });520 it('should not split option values by comma', function() {521 expect(result, 'to have property', 'ignore', [522 '*.test.js',523 '{dirA,dirB}/**/*.spec.js'524 ]);525 });526 });527 });...

Full Screen

Full Screen

find-config.js

Source:find-config.js Github

copy

Full Screen

...8}9test('should find files', async assert => {10 setup();11 const options = {cwd: 'fixtures/a/b'};12 assert.is(findConfig('foo.txt', options), pathResolve('fixtures/a/foo.txt'));13 assert.is(findConfig('bar.txt', options), pathResolve('fixtures/a/b/bar.txt'));14 assert.is(findConfig('a.txt', options), pathResolve('fixtures/a.txt'));15 process.chdir('fixtures/a/b');16 assert.is(findConfig('foo.txt'), pathResolve('../foo.txt'));17 assert.is(findConfig('bar.txt'), pathResolve('./bar.txt'));18 assert.is(findConfig('a.txt'), pathResolve('../../a.txt'));19});20test('should find files in a directory', async assert => {21 setup();22 let options = {cwd: 'fixtures/a/b'};23 assert.is(findConfig('baz.txt', options), pathResolve('fixtures/a/.config/baz.txt'));24 assert.is(findConfig('qux.txt', options), pathResolve('fixtures/a/b/.config/qux.txt'));25 process.chdir('fixtures/a/b');26 assert.is(findConfig('baz.txt', options), pathResolve('../.config/baz.txt'));27 assert.is(findConfig('qux.txt', options), pathResolve('./.config/qux.txt'));28});29test('should find files in a directory', async assert => {30 setup();31 let options = {cwd: 'fixtures/a/b', dir: false};32 assert.is(findConfig('baz.txt', options), null);33 assert.is(findConfig('a.txt', options), pathResolve('fixtures/a.txt'));34 process.chdir('fixtures/a/b');35 options = {dir: false};36 assert.is(findConfig('baz.txt', options), null);37 assert.is(findConfig('a.txt', options), pathResolve('../../a.txt'));38});39test('should drop leading dots in .dir', async assert => {40 setup();41 let options = {cwd: 'fixtures/a/b'};42 assert.is(findConfig('.fred', options), null);43 assert.is(findConfig('.waldo', options), pathResolve('fixtures/.config/waldo'));44 process.chdir('fixtures/a/b');45 assert.is(findConfig('.fred'), null);46 assert.is(findConfig('.waldo'), pathResolve('../../.config/waldo'));47});48test('should keep leading dots in .dir', async assert => {49 setup();50 let options = {cwd: 'fixtures/a/b', dot: true};51 assert.is(findConfig('.fred', options), pathResolve('fixtures/.config/.fred'));52 assert.is(findConfig('.waldo', options), null);53 process.chdir('fixtures/a/b');54 options = {dot: true};55 assert.is(findConfig('.fred', options), pathResolve('../../.config/.fred'));56 assert.is(findConfig('.waldo', options), null);57});58test('should resolve modules', async assert => {59 setup();60 let options = {cwd: 'fixtures/a/b', module: true};61 assert.is(findConfig('b', options), pathResolve('fixtures/b.js'));62 assert.is(findConfig('baz', options), pathResolve('fixtures/a/.config/baz.js'));63 process.chdir('fixtures/a/b');64 options = {module: true};65 assert.is(findConfig('b', options), pathResolve('../../b.js'));66 assert.is(findConfig('baz', options), pathResolve('../.config/baz.js'));67});68test('should not find non-existant files', async assert => {69 setup();70 assert.is(findConfig(), null);71 assert.is(findConfig(null), null);72 assert.is(findConfig(nofile, {home: false}), null);73});74test('should read files', async assert => {75 setup();76 let options = {cwd: 'fixtures/a/b'};77 assert.is(findConfig.read('foo.txt', options), 'foo\n');78 assert.is(findConfig.read('baz.txt', options), 'baz\n');79});80test('should not read non-existant files', async assert => {81 setup();82 assert.is(findConfig.read(), null);83 assert.is(findConfig.read(null), null);84 assert.is(findConfig.read(nofile), null);85 assert.is(findConfig.read(nofile, {home: false}), null);86 assert.throws(() => {...

Full Screen

Full Screen

find-config.unit.test.js

Source:find-config.unit.test.js Github

copy

Full Screen

...5const fixtureDir = join(__dirname, 'fixtures')67describe('find config', () => {8 it('should resolve rc.json', async () => {9 const config = await findConfig(join(fixtureDir, 'config-json'), 'test')10 expect(config).toEqual({ foo: 'bar' })11 })1213 it('should resolve rc.js', async () => {14 const config = await findConfig(join(fixtureDir, 'config-js'), 'test')15 expect(config).toEqual({ foo: 'bar' })16 })1718 it('should resolve .config.json', async () => {19 const config = await findConfig(20 join(fixtureDir, 'config-long-json'),21 'test'22 )23 expect(config).toEqual({ foo: 'bar' })24 })2526 it('should resolve .config.js', async () => {27 const config = await findConfig(join(fixtureDir, 'config-long-js'), 'test')28 expect(config).toEqual({ foo: 'bar' })29 })3031 it('should resolve package.json', async () => {32 const config = await findConfig(33 join(fixtureDir, 'config-package-json'),34 'test'35 )36 expect(config).toEqual({ foo: 'bar' })37 })3839 it('should resolve down', async () => {40 const config = await findConfig(41 join(fixtureDir, 'config-down/one/two/three/'),42 'test'43 )44 expect(config).toEqual({ foo: 'bar' })45 }) ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { findConfig } = require('storybook-root-config');2findConfig('storybook');3const { findConfigSync } = require('storybook-root-config');4findConfigSync('storybook');5const { findConfigSync } = require('storybook-root-config');6findConfigSync('storybook');7const { findConfig } = require('storybook-root-config');8findConfig('storybook');9const { findConfigSync } = require('storybook-root-config');10findConfigSync('storybook');

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const path = require('path');3const configPath = storybookRoot.findConfig(__dirname);4console.log('storybook config path: ', configPath);5console.log('storybook config dir: ', path.dirname(configPath));6const storybookRoot = require('storybook-root');7const path = require('path');8const configPath = storybookRoot.getConfig();9console.log('storybook config path: ', configPath);10console.log('storybook config dir: ', path.dirname(configPath));

Full Screen

Using AI Code Generation

copy

Full Screen

1const findConfig = require('storybook-root-config').findConfig;2const config = findConfig(__dirname);3console.log('config file path is', config);4const path = require('path');5module.exports = {6 webpackFinal: async config => {7 return config;8 },9};10{11 "scripts": {12 },13 "dependencies": {14 }15}16const path = require('path');17module.exports = {18 webpackFinal: async config => {19 return config;20 },21};22{23 "scripts": {24 },25 "dependencies": {26 }27}28const path = require('path');29module.exports = {30 webpackFinal: async config => {31 return config;32 },33};34{

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful