Best JavaScript code snippet using storybook-root
watch-story-specifiers.test.ts
Source: watch-story-specifiers.test.ts
1import { normalizeStoriesEntry } from '@storybook/core-common';2import path from 'path';3import Watchpack from 'watchpack';4import { watchStorySpecifiers } from './watch-story-specifiers';5jest.mock('watchpack');6describe('watchStorySpecifiers', () => {7 const workingDir = path.join(__dirname, '__mockdata__');8 const options = {9 configDir: path.join(workingDir, '.storybook'),10 workingDir,11 };12 let close: () => void;13 afterEach(() => close?.());14 it('watches basic globs', async () => {15 const specifier = normalizeStoriesEntry('../src/**/*.stories.@(ts|js)', options);16 const onInvalidate = jest.fn();17 close = watchStorySpecifiers([specifier], { workingDir }, onInvalidate);18 expect(Watchpack).toHaveBeenCalledTimes(1);19 const watcher = Watchpack.mock.instances[0];20 expect(watcher.watch).toHaveBeenCalledWith({ directories: ['./src'] });21 expect(watcher.on).toHaveBeenCalledTimes(2);22 const onChange = watcher.on.mock.calls[0][1];23 const onRemove = watcher.on.mock.calls[1][1];24 // File changed, matching25 onInvalidate.mockClear();26 await onChange('src/nested/Button.stories.ts', 1234);27 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, false);28 // File changed, NOT matching29 onInvalidate.mockClear();30 await onChange('src/nested/Button.ts', 1234);31 expect(onInvalidate).not.toHaveBeenCalled();32 // File removed, matching33 onInvalidate.mockClear();34 await onRemove('src/nested/Button.stories.ts');35 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, true);36 // File removed, NOT matching37 onInvalidate.mockClear();38 await onRemove('src/nested/Button.ts');39 expect(onInvalidate).not.toHaveBeenCalled();40 // File moved out, matching41 onInvalidate.mockClear();42 await onChange('src/nested/Button.stories.ts', null);43 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, true);44 // File renamed, matching45 onInvalidate.mockClear();46 await onChange('src/nested/Button.stories.ts', null);47 await onChange('src/nested/Button-2.stories.ts', 1234);48 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, true);49 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button-2.stories.ts`, false);50 });51 it('scans directories when they are added', async () => {52 const specifier = normalizeStoriesEntry('../src/**/*.stories.@(ts|js)', options);53 const onInvalidate = jest.fn();54 close = watchStorySpecifiers([specifier], { workingDir }, onInvalidate);55 expect(Watchpack).toHaveBeenCalledTimes(1);56 const watcher = Watchpack.mock.instances[0];57 expect(watcher.watch).toHaveBeenCalledWith({ directories: ['./src'] });58 expect(watcher.on).toHaveBeenCalledTimes(2);59 const onChange = watcher.on.mock.calls[0][1];60 onInvalidate.mockClear();61 await onChange('src/nested', 1234);62 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, false);63 });64 it('watches single file globs', async () => {65 const specifier = normalizeStoriesEntry('../src/nested/Button.stories.mdx', options);66 const onInvalidate = jest.fn();67 close = watchStorySpecifiers([specifier], { workingDir }, onInvalidate);68 expect(Watchpack).toHaveBeenCalledTimes(1);69 const watcher = Watchpack.mock.instances[0];70 expect(watcher.watch).toHaveBeenCalledWith({ directories: ['./src/nested'] });71 expect(watcher.on).toHaveBeenCalledTimes(2);72 const onChange = watcher.on.mock.calls[0][1];73 const onRemove = watcher.on.mock.calls[1][1];74 // File changed, matching75 onInvalidate.mockClear();76 await onChange('src/nested/Button.stories.mdx', 1234);77 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.mdx`, false);78 // File changed, NOT matching79 onInvalidate.mockClear();80 await onChange('src/nested/Button.mdx', 1234);81 expect(onInvalidate).not.toHaveBeenCalled();82 // File removed, matching83 onInvalidate.mockClear();84 await onRemove('src/nested/Button.stories.mdx');85 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.mdx`, true);86 // File removed, NOT matching87 onInvalidate.mockClear();88 await onRemove('src/nested/Button.mdx');89 expect(onInvalidate).not.toHaveBeenCalled();90 // File moved out, matching91 onInvalidate.mockClear();92 await onChange('src/nested/Button.stories.mdx', null);93 expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.mdx`, true);94 });95 it('multiplexes between two specifiers on the same directory', async () => {96 const globSpecifier = normalizeStoriesEntry('../src/**/*.stories.@(ts|js)', options);97 const fileSpecifier = normalizeStoriesEntry('../src/nested/Button.stories.mdx', options);98 const onInvalidate = jest.fn();99 close = watchStorySpecifiers([globSpecifier, fileSpecifier], { workingDir }, onInvalidate);100 expect(Watchpack).toHaveBeenCalledTimes(1);101 const watcher = Watchpack.mock.instances[0];102 expect(watcher.watch).toHaveBeenCalledWith({ directories: ['./src', './src/nested'] });103 expect(watcher.on).toHaveBeenCalledTimes(2);104 const onChange = watcher.on.mock.calls[0][1];105 onInvalidate.mockClear();106 await onChange('src/nested/Button.stories.ts', 1234);107 expect(onInvalidate).toHaveBeenCalledWith(108 globSpecifier,109 `./src/nested/Button.stories.ts`,110 false111 );112 onInvalidate.mockClear();113 await onChange('src/nested/Button.stories.mdx', 1234);114 expect(onInvalidate).toHaveBeenCalledWith(115 fileSpecifier,116 `./src/nested/Button.stories.mdx`,117 false118 );119 });...
findFilesByGlob.ts
Source: findFilesByGlob.ts
1import { workspace } from 'vscode';2import type { GlobSpecifier } from '../config/GlobSpecifier';3import { convertGlobForWorkspace } from '../globs/convertGlobForWorkspace';4import { logDebug } from '../log/log';5export const findFilesByGlob = async (globSpecifier: GlobSpecifier) => {6 const { globPattern, filter } = convertGlobForWorkspace(globSpecifier);7 const findResults = workspace.findFiles(globPattern);8 if (filter) {9 return findResults.then((uris) => {10 logDebug(11 `Found ${uris.length} URIs matching ${12 globSpecifier.files13 } under ${globSpecifier.directory.toString()}`,14 );15 return uris.filter(filter);16 });17 }18 return findResults;...
convertGlobForWorkspace.ts
Source: convertGlobForWorkspace.ts
1import type { GlobSpecifier } from '../config/GlobSpecifier';2import { getRelativePatternForWorkspace } from '../util/getRelativePatternForWorkspace';3import { convertGlob } from './convertGlob';4export const convertGlobForWorkspace = (globSpecifier: GlobSpecifier) => {5 const { globBase, globPattern, filter, regex } = convertGlob(globSpecifier);6 return {7 globPattern: getRelativePatternForWorkspace(globBase, globPattern),8 filter,9 regex,10 };...
Using AI Code Generation
1const { globSpecifier } = require('@storybook/core/server');2module.exports = {3};4module.exports = {5};6module.exports = {7};8module.exports = {9};10module.exports = {
Using AI Code Generation
1import { globSpecifier } from 'storybook-root-config';2import { globSpecifier } from 'storybook-root-config';3import { globSpecifier } from 'storybook-root-config';4import { globSpecifier } from 'storybook-root-config';5import { globSpecifier } from 'storybook-root-config';6import { globSpecifier } from 'storybook-root-config';7import { globSpecifier } from 'storybook-root-config';8import { globSpecifier } from 'storybook-root-config';9import { globSpecifier } from 'storybook-root-config';10import { globSpecifier } from 'storybook-root-config';11import { globSpecifier } from 'storybook-root-config';12import { globSpecifier } from 'storybook-root-config';13import { globSpecifier } from 'storybook-root-config';14import { globSpecifier } from 'storybook-root-config';
Using AI Code Generation
1const storybookRoot = require('storybook-root');2const glob = storybookRoot.globSpecifier('src/components/**/*.stories.js');3module.exports = {4};5const storybookRoot = require('storybook-root');6const glob = storybookRoot.globSpecifier('src/components/**/*.stories.js');7module.exports = {8};
Using AI Code Generation
1const path = require('path');2const glob = require('glob');3const rootAlias = require('storybook-root-alias');4const globSpecifier = rootAlias.getGlobSpecifier();5const files = glob.sync(globSpecifier);6files.forEach(file => {7 const path = rootAlias.resolvePath(file);8 console.log(path);9});10MIT © [Nikunj Gupta](
Using AI Code Generation
1import { globSpecifier } from './storybook-root-config';2export default {3 parameters: {4 notes: { markdown: globSpecifier('Welcome.md') },5 },6};7Please read [CONTRIBUTING.md](
Using AI Code Generation
1import { globSpecifier } from 'storybook-root-config';2const loader = () => {3 return globSpecifier('src/components/**/stories.tsx');4};5export default loader;6import { glob } from 'storybook-root-config';7const loader = () => {8 return glob('src/components/**/stories.tsx');9};10export default loader;11import { glob } from 'storybook-root-config';12const loader = () => {13 return glob('src/components/**/stories.tsx', { ignore: ['src/components/**/stories.tsx'] });14};15export default loader;16import { glob } from 'storybook-root-config';17const loader = () => {18 return glob('src/components/**/stories.tsx', { ignore: ['src/components/**/stories.tsx'], root: 'src' });19};20export default loader;
Using AI Code Generation
1const globSpecifier = require('@storybook/root/dist/cjs/globs/globSpecifier').default;2const glob = globSpecifier({ configDir: './.storybook' });3console.log(glob);4const getManagerHeadHtml = require('@storybook/core-common/dist/cjs/utils/get-manager-head-html').getManagerHeadHtml;5const managerHeadHtml = getManagerHeadHtml({ configDir: './.storybook' });6console.log(managerHeadHtml);
Using AI Code Generation
1const rootConfig = require('storybook-root-config');2const globSpecifier = rootConfig.globSpecifier;3const path = require('path');4const glob = require('glob');5const globPattern = globSpecifier(path.join(__dirname, '../src'), '**/*.stories.js');6const files = glob.sync(globPattern);7files.forEach(file => require(file));8module.exports = {9};
Check out the latest blogs from LambdaTest on this topic:
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.
Estimates are critical if you want to be successful with projects. If you begin with a bad estimating approach, the project will almost certainly fail. To produce a much more promising estimate, direct each estimation-process issue toward a repeatable standard process. A smart approach reduces the degree of uncertainty. When dealing with presales phases, having the most precise estimation findings can assist you to deal with the project plan. This also helps the process to function more successfully, especially when faced with tight schedules and the danger of deviation.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!