How to use namedExports method in storybook-root

Best JavaScript code snippet using storybook-root

interop.test.ts

Source:interop.test.ts Github

copy

Full Screen

1import {2 _interopDefault,3 _interopNamespace,4 _interopNamespaceDefaultOnly,5 _interopRequireDefault,6 _interopRequireWildcard,7} from '../../src/buildPolyfills';8import { RequireResult } from '../../src/buildPolyfills/types';9import {10 _interopDefault as _interopDefaultOrig,11 _interopNamespace as _interopNamespaceOrig,12 _interopNamespaceDefaultOnly as _interopNamespaceDefaultOnlyOrig,13 _interopRequireDefault as _interopRequireDefaultOrig,14 _interopRequireWildcard as _interopRequireWildcardOrig,15} from './originals';16// This file tests five different functions against a range of test cases. Though the inputs are the same for each17// function's test cases, the expected output differs. The testcases for each function are therefore built from separate18// collections of expected inputs and expected outputs. Further, for readability purposes, the tests labels have also19// been split into their own object. It's also worth noting that in real life, there are some test-case/function20// pairings which would never happen, but by testing all combinations, we're guaranteed to have tested the ones which21// show up in the wild.22const dogStr = 'dogs are great!';23const dogFunc = () => dogStr;24const dogAdjectives = { maisey: 'silly', charlie: 'goofy' };25const withESModuleFlag = { __esModule: true, ...dogAdjectives };26const withESModuleFlagAndDefault = { __esModule: true, default: dogFunc, ...dogAdjectives };27const namedExports = { ...dogAdjectives };28const withNonEnumerableProp = { ...dogAdjectives };29// Properties added using `Object.defineProperty` are non-enumerable by default30Object.defineProperty(withNonEnumerableProp, 'hiddenProp', { value: 'shhhhhhhh' });31const withDefaultExport = { default: dogFunc, ...dogAdjectives };32const withOnlyDefaultExport = { default: dogFunc };33const exportsEquals = dogFunc as RequireResult;34const exportsEqualsWithDefault = dogFunc as RequireResult;35exportsEqualsWithDefault.default = exportsEqualsWithDefault;36const mockRequireResults: Record<string, RequireResult> = {37 withESModuleFlag,38 withESModuleFlagAndDefault,39 namedExports,40 withNonEnumerableProp,41 withDefaultExport,42 withOnlyDefaultExport,43 exportsEquals: exportsEquals,44 exportsEqualsWithDefault: exportsEqualsWithDefault as unknown as RequireResult,45};46const testLabels: Record<string, string> = {47 withESModuleFlag: 'module with `__esModule` flag',48 withESModuleFlagAndDefault: 'module with `__esModule` flag and default export',49 namedExports: 'module with named exports',50 withNonEnumerableProp: 'module with named exports and non-enumerable prop',51 withDefaultExport: 'module with default export',52 withOnlyDefaultExport: 'module with only default export',53 exportsEquals: 'module using `exports =`',54 exportsEqualsWithDefault: 'module using `exports =` with default export',55};56function makeTestCases(expectedOutputs: Record<string, RequireResult>): Array<[string, RequireResult, RequireResult]> {57 return Object.keys(mockRequireResults).map(key => [testLabels[key], mockRequireResults[key], expectedOutputs[key]]);58}59describe('_interopNamespace', () => {60 describe('returns the same result as the original', () => {61 const expectedOutputs: Record<string, RequireResult> = {62 withESModuleFlag: withESModuleFlag,63 withESModuleFlagAndDefault: withESModuleFlagAndDefault,64 namedExports: { ...namedExports, default: namedExports },65 withNonEnumerableProp: {66 ...withNonEnumerableProp,67 default: withNonEnumerableProp,68 },69 withDefaultExport: { ...withDefaultExport, default: withDefaultExport },70 withOnlyDefaultExport: { default: withOnlyDefaultExport },71 exportsEquals: { default: exportsEquals },72 exportsEqualsWithDefault: { default: exportsEqualsWithDefault },73 };74 const testCases = makeTestCases(expectedOutputs);75 it.each(testCases)('%s', (_, requireResult, expectedOutput) => {76 expect(_interopNamespace(requireResult)).toEqual(_interopNamespaceOrig(requireResult));77 expect(_interopNamespace(requireResult)).toEqual(expectedOutput);78 });79 });80});81describe('_interopNamespaceDefaultOnly', () => {82 describe('returns the same result as the original', () => {83 const expectedOutputs: Record<string, RequireResult> = {84 withESModuleFlag: { default: withESModuleFlag },85 withESModuleFlagAndDefault: { default: withESModuleFlagAndDefault },86 namedExports: { default: namedExports },87 withNonEnumerableProp: { default: withNonEnumerableProp },88 withDefaultExport: { default: withDefaultExport },89 withOnlyDefaultExport: { default: withOnlyDefaultExport },90 exportsEquals: { default: exportsEquals },91 exportsEqualsWithDefault: { default: exportsEqualsWithDefault },92 };93 const testCases = makeTestCases(expectedOutputs);94 it.each(testCases)('%s', (_, requireResult, expectedOutput) => {95 expect(_interopNamespaceDefaultOnly(requireResult)).toEqual(_interopNamespaceDefaultOnlyOrig(requireResult));96 expect(_interopNamespaceDefaultOnly(requireResult)).toEqual(expectedOutput);97 });98 });99});100describe('_interopRequireWildcard', () => {101 describe('returns the same result as the original', () => {102 const expectedOutputs: Record<string, RequireResult> = {103 withESModuleFlag: withESModuleFlag,104 withESModuleFlagAndDefault: withESModuleFlagAndDefault,105 namedExports: { ...namedExports, default: namedExports },106 withNonEnumerableProp: {107 ...withNonEnumerableProp,108 default: withNonEnumerableProp,109 },110 withDefaultExport: { ...withDefaultExport, default: withDefaultExport },111 withOnlyDefaultExport: { default: withOnlyDefaultExport },112 exportsEquals: { default: exportsEquals },113 exportsEqualsWithDefault: { default: exportsEqualsWithDefault },114 };115 const testCases = makeTestCases(expectedOutputs);116 it.each(testCases)('%s', (_, requireResult, expectedOutput) => {117 expect(_interopRequireWildcard(requireResult)).toEqual(_interopRequireWildcardOrig(requireResult));118 expect(_interopRequireWildcard(requireResult)).toEqual(expectedOutput);119 });120 });121});122describe('_interopDefault', () => {123 describe('returns the same result as the original', () => {124 const expectedOutputs: Record<string, RequireResult> = {125 withESModuleFlag: undefined as unknown as RequireResult,126 withESModuleFlagAndDefault: withESModuleFlagAndDefault.default as RequireResult,127 namedExports: namedExports,128 withNonEnumerableProp: withNonEnumerableProp,129 withDefaultExport: withDefaultExport,130 withOnlyDefaultExport: withOnlyDefaultExport,131 exportsEquals: exportsEquals,132 exportsEqualsWithDefault: exportsEqualsWithDefault,133 };134 const testCases = makeTestCases(expectedOutputs);135 it.each(testCases)('%s', (_, requireResult, expectedOutput) => {136 expect(_interopDefault(requireResult)).toEqual(_interopDefaultOrig(requireResult));137 expect(_interopDefault(requireResult)).toEqual(expectedOutput);138 });139 });140});141describe('_interopRequireDefault', () => {142 describe('returns the same result as the original', () => {143 const expectedOutputs: Record<string, RequireResult> = {144 withESModuleFlag: withESModuleFlag,145 withESModuleFlagAndDefault: withESModuleFlagAndDefault,146 namedExports: { default: namedExports },147 withNonEnumerableProp: { default: withNonEnumerableProp },148 withDefaultExport: { default: withDefaultExport },149 withOnlyDefaultExport: { default: withOnlyDefaultExport },150 exportsEquals: { default: exportsEquals },151 exportsEqualsWithDefault: { default: exportsEqualsWithDefault },152 };153 const testCases = makeTestCases(expectedOutputs);154 it.each(testCases)('%s', (_, requireResult, expectedOutput) => {155 expect(_interopRequireDefault(requireResult)).toEqual(_interopRequireDefaultOrig(requireResult));156 expect(_interopRequireDefault(requireResult)).toEqual(expectedOutput);157 });158 });...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1#!/usr/bin/env node2import chalk from 'chalk';3import yargs from 'yargs';4import { hideBin } from 'yargs/helpers';5import fs from 'fs-extra';6import glob from 'fast-glob';7import postcss from 'postcss';8import postcssrc from 'postcss-load-config';9import DtsCreator from 'typed-css-modules';10import path from 'path';11// eslint-disable-next-line @typescript-eslint/no-empty-function12const logger = (enable: boolean) => (enable ? console.log : () => {});13const COMPILED_CSS_PREFIX = '__postcss__';14const TYPE_DEF_FILE_EXT = 'd.ts';15type Params = {16 verbose: boolean;17 configPath?: string;18 keep?: boolean;19 namedExports: boolean;20};21const run = async (22 source: string,23 { verbose, configPath, namedExports, keep = false }: Params24) => {25 const log = logger(verbose);26 log(chalk.greenBright(`\nGenerating d.ts for "${source}"\n`));27 if (keep)28 log(29 chalk.bgYellowBright.red(30 '\nAttention, you are preserving compiled css files!\n'31 )32 );33 try {34 const filesMatch = await glob(source);35 const cssModules = filesMatch.filter(36 (p) => !p.includes(COMPILED_CSS_PREFIX)37 );38 if (!cssModules.length) {39 throw new Error(40 'No files were found to compile, please check your glob pattern'41 );42 }43 const { plugins, file } = await postcssrc(undefined, configPath);44 log(chalk.cyan(`Loaded PostCSS config file from path: \n${file}`));45 log(46 chalk.bgMagenta(47 `\nFound ${cssModules.length} file${48 cssModules.length === 1 ? '' : 's'49 } to process\n`50 )51 );52 const creator = new DtsCreator({53 camelCase: true,54 namedExports,55 });56 for (const cssModuleFilePath of cssModules) {57 log(chalk.yellowBright(`\ncompiling ${cssModuleFilePath}`));58 const compiledCSSFilePath = `${path.dirname(59 cssModuleFilePath60 )}/${COMPILED_CSS_PREFIX}${path.basename(cssModuleFilePath)}`;61 const css = await fs.readFile(cssModuleFilePath, 'utf-8');62 const compiled = await postcss(plugins).process(css, {63 from: undefined,64 });65 await fs.writeFile(compiledCSSFilePath, compiled.css);66 log(chalk.magenta(`compiled ${compiledCSSFilePath}`));67 const dtsContent = await creator.create(compiledCSSFilePath);68 await dtsContent.writeFile();69 if (!keep) {70 await fs.remove(compiledCSSFilePath);71 log(72 chalk.grey(`compiled file has been removed ${compiledCSSFilePath}`)73 );74 }75 const dtsFilename = `${compiledCSSFilePath.replace(76 COMPILED_CSS_PREFIX,77 ''78 )}.${TYPE_DEF_FILE_EXT}`;79 await fs.rename(80 `${compiledCSSFilePath}.${TYPE_DEF_FILE_EXT}`,81 dtsFilename82 );83 log(chalk.green(`generated d.ts ${dtsFilename}\n`));84 }85 } catch (error) {86 log(chalk.red(`An error occurred during generation: ${error}`));87 }88};89yargs(hideBin(process.argv))90 .group(['verbose', 'config', 'keep'], 'Basic options:')91 .option('verbose', {92 alias: 'v',93 type: 'boolean',94 description: 'Run with verbose logging',95 })96 .option('config', {97 alias: 'c',98 type: 'string',99 demandOption: false,100 description: 'Optionally provide custom path to your PostCSS config',101 })102 .option('keep', {103 alias: 'k',104 type: 'boolean',105 demandOption: false,106 description: 'Keep compiled css files',107 })108 .group(['namedExports'], 'typed-css-modules options:')109 .option('namedExports', {110 alias: 'n',111 type: 'boolean',112 default: false,113 description: 'Enables named export for generated d.ts files',114 })115 .command(116 '$0 <source> [options]',117 'Generate d.ts files for PostCSS powered css modules',118 (yargs) =>119 yargs.positional('source', {120 describe: 'source pattern to your css modules files location',121 type: 'string',122 }),123 async (argv) => {124 await run(argv.source, {125 verbose: argv.verbose,126 configPath: argv.config,127 keep: argv.keep,128 namedExports: argv.namedExports,129 });130 }131 )132 .example(133 'pcssmdts "src/**/*.module.css"',134 'Basic usage, in the end next to each found css file corresponding d.ts file will be generated\n\n'135 )136 .example(137 'pcssmdts "src/**/*.module.css" -k',138 'In this case compiled files will be preserved, all compiled files are prefixed by __postcss__\n\n'139 )140 .example(141 'pcssmdts "src/**/*.module.css" -c configs/postcss.config.js',142 'Custom PostCSS config location path\n\n'143 )144 .example(145 'pcssmdts "src/**/*.module.css" -n',146 'Named exports is used for generated files\n\n'147 )...

Full Screen

Full Screen

ImportDeclaration.ts

Source:ImportDeclaration.ts Github

copy

Full Screen

1export interface IImportDeclarationConfig {2 defaultExport?: string;3 namedExports: string[];4 moduleName: string;5}6export default class ImportDeclaration {7 public defaultExport?: string;8 public namedExports: string[];9 public moduleName: string;10 /**11 * Creates an import declaration.12 */13 constructor(config: IImportDeclarationConfig) {14 const { defaultExport, namedExports, moduleName } = config;15 this.defaultExport = defaultExport;16 this.namedExports = namedExports;17 this.moduleName = moduleName;18 }19 public toString() {20 let str;21 if (this.defaultExport) {22 str = `const ${this.defaultExport} = require('${this.moduleName}');`;23 } else if (this.namedExports && this.namedExports.length) {24 str = `const { ${this.namedExports.join(', ')} } = require('${this.moduleName}');`;25 } else {26 str = `require('${this.moduleName}');`;27 }28 return str;29 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2import { setDefaults } from 'storybook-addon-jsx';3import { setOptions } from '@storybook/addon-options';4import { setDefaults as setAddonInfo } from '@storybook/addon-info';5import { setDefaults as setConsoleOptions } from '@storybook/addon-console';6import { setOptions as setKnobsOptions } from '@storybook/addon-knobs';7import { setDefaults as setViewportOptions } from '@storybook/addon-viewport';8import { setDefaults as setOptions as setA11yOptions } from '@storybook/addon-a11y';

Full Screen

Using AI Code Generation

copy

Full Screen

1const rootImport = require('storybook-root-import');2const path = require('path');3module.exports = {4 webpackFinal: async (config) => {5 config.resolve.plugins = config.resolve.plugins || [];6 config.resolve.plugins.push(7 new rootImport({8 rootPathSuffix: path.resolve(__dirname, '../'),9 }),10 );11 return config;12 },13};14import { rootImport } from './test';15rootImport();16import { rootImport } from '../test';17rootImport();18const rootImport = require('storybook-root-import');19const path = require('path');20module.exports = async ({ config }) => {21 config.resolve.plugins = config.resolve.plugins || [];22 config.resolve.plugins.push(23 new rootImport({24 rootPathSuffix: path.resolve(__dirname, '../'),25 }),26 );27 return config;28};29const rootImport = require('storybook-root-import');30const path = require('path');31module.exports = {32 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],33 webpackFinal: async (config) => {34 config.resolve.plugins = config.resolve.plugins || [];35 config.resolve.plugins.push(36 new rootImport({37 rootPathSuffix: path.resolve(__dirname, '../'),38 }),39 );40 return config;41 },42};43{44 "compilerOptions": {45 "paths": {46 }47 }48}49{50 "compilerOptions": {51 "paths": {52 }53 }54}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2configure(require.context('../src', true, /\.stories\.js$/), module);3import { configure } from '@storybook/react';4configure(require.context('../src', true, /\.stories\.js$/), module);5import { configure } from '@storybook/react';6configure(require.context('../src', true, /\.stories\.js$/), module);7import { configure } from '@storybook/react';8configure(require.context('../src', true, /\.stories\.js$/), module);9import { configure } from '@storybook/react';10configure(require.context('../src', true, /\.stories\.js$/), module);11import { configure } from '@storybook/react';12configure(require.context('../src', true, /\.stories\.js$/), module);13import { configure } from '@storybook/react';14configure(require.context('../src', true, /\.stories\.js$/), module);15import { configure } from '@storybook/react';16configure(require.context('../src', true, /\.stories\.js$/), module);17import { configure } from '@storybook/react';18configure(require.context('../src', true, /\.stories\.js$/), module);19import { configure } from '@storybook/react';20configure(require.context('../src', true, /\.stories\.js$/), module);21import { configure } from '@storybook/react';22configure(require.context('../src', true, /\.stories\.js$/), module);23import { configure } from '@storybook/react';24configure(require.context('../src', true, /\.stories\.js$/), module);25import { configure } from '@storybook/react';26configure(require.context('../src', true, /\.stories\.js$/), module);

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { addRootAlias } = require('storybook-root-alias');3module.exports = function({ config }) {4 addRootAlias(config, {5 root: path.resolve(__dirname, '..', '..'),6 aliases: {7 '@storybook': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook'),8 '@storybook/addon-knobs': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-knobs'),9 '@storybook/addon-actions': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-actions'),10 '@storybook/addon-links': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-links'),11 '@storybook/addon-notes': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-notes'),12 '@storybook/addon-storysource': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-storysource'),13 '@storybook/addon-viewport': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-viewport'),14 '@storybook/addon-a11y': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-a11y'),15 '@storybook/addon-backgrounds': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-backgrounds'),16 '@storybook/react': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'react'),17 '@storybook/addon-options': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-options'),18 '@storybook/addon-info': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-info'),19 '@storybook/addon-jest': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-jest'),20 '@storybook/addon-options': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-options'),21 '@storybook/addon-storyshots': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-storyshots'),22 '@storybook/addon-storyshots-puppeteer': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-storyshots-puppeteer'),23 '@storybook/addon-storyshots/injectFileName': path.resolve(__dirname, '..', '..', 'node_modules', '@storybook', 'addon-storyshots',

Full Screen

Using AI Code Generation

copy

Full Screen

1import { namedExports } from 'storybook-root-alias';2const rootAlias = namedExports({3 '@components': path.resolve(__dirname, '../src/components'),4 '@assets': path.resolve(__dirname, '../src/assets'),5 '@utils': path.resolve(__dirname, '../src/utils'),6 '@styles': path.resolve(__dirname, '../src/styles'),7});8export default rootAlias;9const rootAlias = require('./test.js');10module.exports = {11 webpackFinal: async (config) => {12 config.resolve.plugins = config.resolve.plugins.filter(13 (plugin) => plugin.constructor.name !== 'ModuleScopePlugin'14 );15 config.resolve.alias = {16 };17 return config;18 },19};20import { withTests } from '@storybook/addon-jest';21import results from '../.jest-test-results.json';22addDecorator(23 withTests({24 filesExt: '((\\.specs?)|(\\.tests?))?(\\.ts|\\.tsx)?$',25 })26);27addParameters({28 jest: {29 filesExt: '((\\.specs?)|(\\.tests?))?(\\.ts|\\.tsx)?$',30 },31});32const rootAlias = require('./test.js');33module.exports = (baseConfig, env, config) => {34 config.resolve.plugins = config.resolve.plugins.filter(35 (plugin) => plugin.constructor.name !== 'ModuleScopePlugin'36 );37 config.resolve.alias = {38 };39 return config;40};41{42 "compilerOptions": {43 "paths": {44 }45 },

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2import { configureRootAlias } from 'storybook-root-alias';3configureRootAlias({4 root: path.resolve(__dirname, '../src'),5 namedExports: {6 }7});8configure(require.context('../src', true, /\.stories\.js$/), module);9{10 "scripts": {11 }12}13import { configure } from '@storybook/react';14import { configureRootAlias } from 'storybook-root-alias';15configureRootAlias({16 root: path.resolve(__dirname, '../src'),17 namedExports: {18 }19});20configure(require.context('../src', true, /\.stories\.js$/), module);21import 'storybook-root-alias/register';22const path = require('path');23const { configureRootAlias } = require('storybook-root-alias');24module.exports = (baseConfig, env, defaultConfig) => {25 configureRootAlias({26 root: path.resolve(__dirname, '../src'),27 namedExports: {28 }29 });30 return defaultConfig;31};

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