react-cosmos 6.1.2-canary.fbe721b.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/dist/client.d.ts +2 -1
  3. package/dist/client.js +1 -1
  4. package/dist/corePlugins/fixtureWatcherPlugin.js +4 -4
  5. package/dist/corePlugins/fixturesJsonPlugin.js +16 -14
  6. package/dist/corePlugins/index.js +2 -2
  7. package/dist/cosmosPlugin/types.d.ts +0 -1
  8. package/dist/devServer/httpServer.d.ts +0 -2
  9. package/dist/devServer/messageHandler.d.ts +0 -1
  10. package/dist/getFixtures/getFixtures.d.ts +1 -1
  11. package/dist/getFixtures/getFixtures.js +6 -5
  12. package/dist/getFixtures/importUserModules.d.ts +1 -1
  13. package/dist/getFixtures/importUserModules.js +8 -8
  14. package/dist/index.d.ts +0 -1
  15. package/dist/index.js +0 -1
  16. package/dist/shared/playgroundHtml.js +2 -2
  17. package/dist/shared/serverFixtureList.d.ts +1 -1
  18. package/dist/shared/serverFixtureList.js +2 -2
  19. package/dist/shared/staticPath.js +9 -2
  20. package/dist/testHelpers/mockConsole.js +2 -1
  21. package/dist/testHelpers/mockFetch.d.ts +2 -2
  22. package/dist/testHelpers/mockFetch.js +2 -1
  23. package/dist/testHelpers/mockFs.d.ts +4 -4
  24. package/dist/testHelpers/mockFs.js +14 -13
  25. package/dist/testHelpers/mockYargs.d.ts +2 -2
  26. package/dist/testHelpers/mockYargs.js +13 -9
  27. package/dist/userModules/findUserModulePaths.d.ts +1 -1
  28. package/dist/userModules/findUserModulePaths.js +3 -3
  29. package/dist/utils/isNodeError.d.ts +0 -1
  30. package/dist/utils/requireModule.d.ts +0 -1
  31. package/dist/utils/requireModule.js +0 -8
  32. package/dist/utils/resolve.js +0 -2
  33. package/package.json +11 -11
  34. package/vitest.d.ts +1 -0
  35. package/vitest.js +1 -0
  36. package/dist/cjsMocks/requireModule.d.ts +0 -2
  37. package/dist/cjsMocks/requireModule.js +0 -7
  38. package/dist/cjsMocks/resolve.d.ts +0 -2
  39. package/dist/cjsMocks/resolve.js +0 -7
  40. package/dist/cjsMocks/staticPath.d.ts +0 -1
  41. package/dist/cjsMocks/staticPath.js +0 -4
  42. package/dist/utils/requireSilent.d.ts +0 -1
  43. package/dist/utils/requireSilent.js +0 -11
  44. package/jest.d.ts +0 -1
  45. package/jest.js +0 -1
  46. /package/dist/{jest.d.ts → vitest.d.ts} +0 -0
  47. /package/dist/{jest.js → vitest.js} +0 -0
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  <a aria-label="Codecov" href="https://app.codecov.io/gh/react-cosmos/react-cosmos"><img src="https://img.shields.io/codecov/c/github/react-cosmos/react-cosmos?colorA=000000&colorB=000000" alt="" /></a>
10
10
  <a aria-label="Twitter" href="https://twitter.com/ReactCosmos"><img src="https://img.shields.io/badge/twitter-follow-%2300acee?colorA=000000&colorB=000000" alt="" /></a>
11
11
  <a aria-label="Discord" href="https://discord.gg/3X95VgfnW5"><img src="https://img.shields.io/discord/620737684859781150?label=discord&logo=discord&logoColor=ffffff&colorA=000000&colorB=000000" alt="" /></a>
12
- <a aria-label="PRs Welcome" href="https://github.com/react-cosmos/react-cosmos/blob/main/CONTRIBUTING.md#how-to-contribute"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?colorA=000000&colorB=000000" alt="" /></a>
12
+ <a aria-label="PRs Welcome" href="https://github.com/react-cosmos/react-cosmos/blob/main/.github/CONTRIBUTING.md#how-to-contribute"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?colorA=000000&colorB=000000" alt="" /></a>
13
13
  </p>
14
14
 
15
15
  ## Getting Started
package/dist/client.d.ts CHANGED
@@ -1 +1,2 @@
1
- export { FixtureContext, Viewport, useFixtureInput, useFixtureSelect, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';
1
+ export { DecoratorProps } from 'react-cosmos-core';
2
+ export { ClassStateMock, FixtureContext, Viewport, useFixtureInput, useFixtureSelect, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- export { FixtureContext, Viewport, useFixtureInput, useFixtureSelect, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';
1
+ export { ClassStateMock, FixtureContext, Viewport, useFixtureInput, useFixtureSelect, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';
@@ -12,11 +12,11 @@ export const fixtureWatcherPlugin = {
12
12
  async devServer({ cosmosConfig, platform }) {
13
13
  const exposeImports = shouldExposeImports(platform, cosmosConfig);
14
14
  if (exposeImports) {
15
- const modulePaths = findUserModulePaths(cosmosConfig);
15
+ const modulePaths = await findUserModulePaths(cosmosConfig);
16
16
  await generateImportsFile(cosmosConfig, 'dev', modulePaths);
17
17
  }
18
- const watcher = await startFixtureWatcher(cosmosConfig, 'all', () => {
19
- const modulePaths = findUserModulePaths(cosmosConfig);
18
+ const watcher = await startFixtureWatcher(cosmosConfig, 'all', async () => {
19
+ const modulePaths = await findUserModulePaths(cosmosConfig);
20
20
  updateFixtureListCache(cosmosConfig.rootDir, modulePaths.fixturePaths);
21
21
  if (exposeImports) {
22
22
  generateImportsFile(cosmosConfig, 'dev', modulePaths);
@@ -28,7 +28,7 @@ export const fixtureWatcherPlugin = {
28
28
  },
29
29
  async export({ cosmosConfig }) {
30
30
  if (shouldExposeImports('web', cosmosConfig)) {
31
- const modulePaths = findUserModulePaths(cosmosConfig);
31
+ const modulePaths = await findUserModulePaths(cosmosConfig);
32
32
  await generateImportsFile(cosmosConfig, 'export', modulePaths);
33
33
  }
34
34
  },
@@ -1,3 +1,4 @@
1
+ import { sortBy } from 'lodash-es';
1
2
  import fs from 'node:fs/promises';
2
3
  import path from 'node:path';
3
4
  import { createRendererUrl, pickRendererUrl, removeFixtureNameExtension, removeFixtureNameSuffix, } from 'react-cosmos-core';
@@ -6,17 +7,17 @@ import { importKeyPath } from '../userModules/shared.js';
6
7
  export const fixturesJsonPlugin = {
7
8
  name: 'fixturesJson',
8
9
  devServer({ cosmosConfig, expressApp }) {
9
- expressApp.get('/cosmos.fixtures.json', (req, res) => {
10
- res.json(createFixtureItems(cosmosConfig, 'dev'));
10
+ expressApp.get('/cosmos.fixtures.json', async (req, res) => {
11
+ res.json(await createFixtureItems(cosmosConfig, 'dev'));
11
12
  });
12
13
  },
13
14
  async export({ cosmosConfig }) {
14
15
  const { exportPath } = cosmosConfig;
15
- const json = createFixtureItems(cosmosConfig, 'export');
16
+ const json = await createFixtureItems(cosmosConfig, 'export');
16
17
  await fs.writeFile(path.join(exportPath, 'cosmos.fixtures.json'), JSON.stringify(json, null, 2));
17
18
  },
18
19
  };
19
- function createFixtureItems(cosmosConfig, command) {
20
+ async function createFixtureItems(cosmosConfig, command) {
20
21
  const rendererUrl = pickRendererUrl(cosmosConfig.rendererUrl, command);
21
22
  if (!rendererUrl) {
22
23
  return {
@@ -25,18 +26,19 @@ function createFixtureItems(cosmosConfig, command) {
25
26
  };
26
27
  }
27
28
  const { fixturesDir, fixtureFileSuffix } = cosmosConfig;
28
- const { fixturePaths } = findUserModulePaths(cosmosConfig);
29
+ const { fixturePaths } = await findUserModulePaths(cosmosConfig);
30
+ const fixtures = fixturePaths.map(filePath => {
31
+ const relPath = importKeyPath(filePath, cosmosConfig.rootDir);
32
+ const fixtureId = { path: relPath };
33
+ return {
34
+ filePath: relPath,
35
+ cleanPath: cleanFixturePath(relPath, fixturesDir, fixtureFileSuffix),
36
+ rendererUrl: createRendererUrl(rendererUrl, fixtureId, true),
37
+ };
38
+ });
29
39
  return {
30
40
  rendererUrl,
31
- fixtures: fixturePaths.map(filePath => {
32
- const relPath = importKeyPath(filePath, cosmosConfig.rootDir);
33
- const fixtureId = { path: relPath };
34
- return {
35
- filePath: relPath,
36
- cleanPath: cleanFixturePath(relPath, fixturesDir, fixtureFileSuffix),
37
- rendererUrl: createRendererUrl(rendererUrl, fixtureId, true),
38
- };
39
- }),
41
+ fixtures: sortBy(fixtures, f => f.cleanPath.join('-')),
40
42
  };
41
43
  }
42
44
  function cleanFixturePath(filePath, fixturesDir, fixtureSuffix) {
@@ -11,7 +11,7 @@ export const coreServerPlugins = [
11
11
  openFilePlugin,
12
12
  pluginEndpointPlugin,
13
13
  ];
14
- // Omit starting chokidar in Jest tests for performance reasons
15
- if (process.env.JEST_WORKER_ID === undefined) {
14
+ // Omit starting chokidar in unit tests for performance reasons
15
+ if (process.env.VITEST_WORKER_ID === undefined) {
16
16
  coreServerPlugins.push(fixtureWatcherPlugin);
17
17
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import express from 'express';
3
2
  import http from 'http';
4
3
  import { CosmosCommand, MessageType } from 'react-cosmos-core';
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import http from 'http';
4
2
  import https from 'https';
5
3
  import { CosmosConfig } from '../cosmosConfig/types.js';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import http from 'http';
3
2
  import { ServerMessage } from 'react-cosmos-core';
4
3
  export declare function createMessageHandler(httpServer: http.Server): {
@@ -14,5 +14,5 @@ export type FixtureApi = {
14
14
  type Options = {
15
15
  rendererUrl?: string;
16
16
  };
17
- export declare function getFixtures(cosmosConfig: CosmosConfig, options?: Options): FixtureApi[];
17
+ export declare function getFixtures(cosmosConfig: CosmosConfig, options?: Options): Promise<FixtureApi[]>;
18
18
  export {};
@@ -4,13 +4,14 @@ import { buildPlaygroundQueryString, createFixtureTree, createRendererUrl, flatt
4
4
  import { createFixtureNode, decorateFixture } from 'react-cosmos-renderer';
5
5
  import { getPlaygroundUrl } from '../shared/playgroundUrl.js';
6
6
  import { importUserModules } from './importUserModules.js';
7
- export function getFixtures(cosmosConfig, options = {}) {
8
- const { fixtures, decorators } = importUserModules(cosmosConfig);
7
+ export async function getFixtures(cosmosConfig, options = {}) {
8
+ const { fixtures, decorators } = await importUserModules(cosmosConfig);
9
9
  const fixtureExports = mapValues(fixtures, f => f.default);
10
10
  const decoratorExports = mapValues(decorators, f => f.default);
11
11
  const result = [];
12
12
  getFlatFixtureTree(cosmosConfig, fixtureExports).forEach(({ fileName, fixtureId, name, parents }) => {
13
13
  const fixtureExport = fixtures[fixtureId.path].default;
14
+ const fixtureOptions = fixtures[fixtureId.path].options ?? {};
14
15
  const fixture = getFixtureFromExport(fixtureExport, fixtureId.name);
15
16
  if (!fixture) {
16
17
  throw new Error(`Could not read fixture: ${JSON.stringify(fixtureId)}`);
@@ -21,7 +22,7 @@ export function getFixtures(cosmosConfig, options = {}) {
21
22
  result.push({
22
23
  absoluteFilePath: path.join(cosmosConfig.rootDir, fixtureId.path),
23
24
  fileName,
24
- getElement: createFixtureElementGetter(fixture, fixtureId.path, decoratorExports),
25
+ getElement: createFixtureElementGetter(fixture, fixtureOptions, fixtureId.path, decoratorExports),
25
26
  name,
26
27
  parents,
27
28
  playgroundUrl: getPlaygroundFixtureUrl(cosmosConfig, fixtureId),
@@ -47,7 +48,7 @@ function getPlaygroundFixtureUrl(cosmosConfig, fixtureId) {
47
48
  const query = buildPlaygroundQueryString({ fixtureId });
48
49
  return `${baseUrl}/${query}`;
49
50
  }
50
- function createFixtureElementGetter(fixture, fixturePath, decoratorsByPath) {
51
+ function createFixtureElementGetter(fixture, fixtureOptions, fixturePath, decoratorsByPath) {
51
52
  const decorators = getSortedDecoratorsForFixturePath(fixturePath, decoratorsByPath);
52
- return () => decorateFixture(createFixtureNode(fixture), decorators);
53
+ return () => decorateFixture(createFixtureNode(fixture), fixtureOptions, decorators.flat());
53
54
  }
@@ -4,5 +4,5 @@ type UserModules = {
4
4
  fixtures: ByPath<ReactFixtureModule>;
5
5
  decorators: ByPath<ReactDecoratorModule>;
6
6
  };
7
- export declare function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: CosmosConfig): UserModules;
7
+ export declare function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: CosmosConfig): Promise<UserModules>;
8
8
  export {};
@@ -1,22 +1,22 @@
1
1
  import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
2
2
  import { importKeyPath } from '../userModules/shared.js';
3
- export function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
4
- const { fixturePaths, decoratorPaths } = findUserModulePaths({
3
+ export async function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
4
+ const { fixturePaths, decoratorPaths } = await findUserModulePaths({
5
5
  rootDir,
6
6
  fixturesDir,
7
7
  fixtureFileSuffix,
8
8
  ignore,
9
9
  });
10
10
  return {
11
- fixtures: importModules(fixturePaths, rootDir),
12
- decorators: importModules(decoratorPaths, rootDir),
11
+ fixtures: await importModules(fixturePaths, rootDir),
12
+ decorators: await importModules(decoratorPaths, rootDir),
13
13
  };
14
14
  }
15
- function importModules(paths, rootDir) {
16
- const modules = paths.map(p => {
15
+ async function importModules(paths, rootDir) {
16
+ const modules = await Promise.all(paths.map(async (p) => {
17
17
  const relPath = importKeyPath(p, rootDir);
18
- return { relPath, module: require(p) };
19
- });
18
+ return { relPath, module: await import(p) };
19
+ }));
20
20
  return modules.reduce((acc, { relPath, module }) => ({
21
21
  ...acc,
22
22
  [relPath]: module,
package/dist/index.d.ts CHANGED
@@ -16,7 +16,6 @@ export * from './userModules/fixtureWatcher.js';
16
16
  export * from './userModules/generateUserImports.js';
17
17
  export * from './utils/cli.js';
18
18
  export * from './utils/fs.js';
19
- export * from './utils/requireSilent.js';
20
19
  export * from './utils/resolve.js';
21
20
  export * from './utils/resolveLoose.js';
22
21
  export * from './utils/resolveSilent.js';
package/dist/index.js CHANGED
@@ -15,7 +15,6 @@ export * from './userModules/fixtureWatcher.js';
15
15
  export * from './userModules/generateUserImports.js';
16
16
  export * from './utils/cli.js';
17
17
  export * from './utils/fs.js';
18
- export * from './utils/requireSilent.js';
19
18
  export * from './utils/resolve.js';
20
19
  export * from './utils/resolveLoose.js';
21
20
  export * from './utils/resolveSilent.js';
@@ -12,7 +12,7 @@ export async function getDevPlaygroundHtml(platform, cosmosConfig, pluginConfigs
12
12
  ...ui,
13
13
  core: await getCoreConfig(cosmosConfig, true),
14
14
  rendererCore: {
15
- fixtures: getServerFixtureList(cosmosConfig),
15
+ fixtures: await getServerFixtureList(cosmosConfig),
16
16
  rendererUrl: platform === 'web'
17
17
  ? pickRendererUrl(cosmosConfig.rendererUrl, 'dev')
18
18
  : null,
@@ -28,7 +28,7 @@ export async function getExportPlaygroundHtml(cosmosConfig, pluginConfigs) {
28
28
  ...ui,
29
29
  core: await getCoreConfig(cosmosConfig, false),
30
30
  rendererCore: {
31
- fixtures: getServerFixtureList(cosmosConfig),
31
+ fixtures: await getServerFixtureList(cosmosConfig),
32
32
  rendererUrl: pickRendererUrl(cosmosConfig.rendererUrl, 'export'),
33
33
  },
34
34
  },
@@ -1,4 +1,4 @@
1
1
  import { FixtureList } from 'react-cosmos-core';
2
2
  import { CosmosConfig } from '../cosmosConfig/types.js';
3
- export declare function getServerFixtureList(cosmosConfig: CosmosConfig): FixtureList;
3
+ export declare function getServerFixtureList(cosmosConfig: CosmosConfig): Promise<FixtureList>;
4
4
  export declare function updateFixtureListCache(rootDir: string, fixturePaths: string[]): void;
@@ -1,9 +1,9 @@
1
1
  import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
2
2
  import { importKeyPath } from '../userModules/shared.js';
3
3
  let fixtureListCache = null;
4
- export function getServerFixtureList(cosmosConfig) {
4
+ export async function getServerFixtureList(cosmosConfig) {
5
5
  if (!fixtureListCache) {
6
- const { fixturePaths } = findUserModulePaths(cosmosConfig);
6
+ const { fixturePaths } = await findUserModulePaths(cosmosConfig);
7
7
  fixtureListCache = createFixtureList(cosmosConfig.rootDir, fixturePaths);
8
8
  }
9
9
  return fixtureListCache;
@@ -1,4 +1,11 @@
1
- import { fileURLToPath } from 'url';
1
+ import { fileURLToPath } from 'node:url';
2
2
  export function getStaticPath(relPath) {
3
- return fileURLToPath(new URL(`../static/${relPath}`, import.meta.url));
3
+ // baseUrl is stored in a variable to bypass Vite's regex-based replacement
4
+ // of `import.meta.url` with self.location in jsdom environments.
5
+ // https://github.com/vitest-dev/vitest/issues/3988#issuecomment-1686450535
6
+ // Why would this code be running in a jsdom environment? Some server tests
7
+ // use a jsdom environment in order to simulate WebSocket connections.
8
+ // This code only runs on the server in production.
9
+ const baseUrl = import.meta.url;
10
+ return fileURLToPath(new URL(`../static/${relPath}`, baseUrl));
4
11
  }
@@ -1,7 +1,8 @@
1
+ import { vi } from 'vitest';
1
2
  export async function mockConsole(cb) {
2
3
  const expectedLogs = [];
3
4
  const origConsoleLog = console.log;
4
- console.log = jest.fn((...args) => {
5
+ console.log = vi.fn((...args) => {
5
6
  if (typeof args[0] !== 'string' || !expectedLogs.includes(args[0])) {
6
7
  origConsoleLog(...args);
7
8
  }
@@ -1,2 +1,2 @@
1
- /// <reference types="jest" />
2
- export declare function mockFetch(httpStatus: number, cb: (fetchMock: jest.Mock) => Promise<unknown>): Promise<void>;
1
+ import { Mock } from 'vitest';
2
+ export declare function mockFetch(httpStatus: number, cb: (fetchMock: Mock) => Promise<unknown>): Promise<void>;
@@ -1,7 +1,8 @@
1
+ import { vi } from 'vitest';
1
2
  export async function mockFetch(httpStatus, cb) {
2
3
  const w = window;
3
4
  const origFetch = window.fetch;
4
- w.fetch = jest.fn(async () => ({ status: httpStatus }));
5
+ w.fetch = vi.fn(async () => ({ status: httpStatus }));
5
6
  await cb(w.fetch);
6
7
  w.fetch = origFetch;
7
8
  }
@@ -1,5 +1,5 @@
1
1
  import { CosmosConfig } from '../cosmosConfig/types.js';
2
- export declare function mockFile(filePath: string, fileMock: {}): void;
3
- export declare function mockCosmosConfig(cosmosConfigPath: string, cosmosConfig: Partial<CosmosConfig>): void;
4
- export declare function mockCwdModuleDefault(filePath: string, fileMock: {}): void;
5
- export declare function resetFsMock(): void;
2
+ export declare function mockFile(filePath: string, fileMock: {}): Promise<void>;
3
+ export declare function mockCosmosConfig(cosmosConfigPath: string, cosmosConfig: Partial<CosmosConfig>): Promise<void>;
4
+ export declare function mockCwdModuleDefault(filePath: string, fileMock: {}): Promise<void>;
5
+ export declare function resetFsMock(): Promise<void>;
@@ -1,7 +1,8 @@
1
1
  import path from 'node:path';
2
+ import { vi } from 'vitest';
2
3
  import { getCwdPath } from './cwd.js';
3
- jest.mock('../utils/fs', () => {
4
- const actual = jest.requireActual('../utils/fs');
4
+ vi.mock('../utils/fs', async () => {
5
+ const actual = (await vi.importActual('../utils/fs'));
5
6
  let mocked = false;
6
7
  let fileMocks = {};
7
8
  let dirMocks = [];
@@ -62,21 +63,21 @@ jest.mock('../utils/fs', () => {
62
63
  },
63
64
  };
64
65
  });
65
- export function mockFile(filePath, fileMock) {
66
- requireMocked().__mockFile(filePath, fileMock);
67
- requireMocked().__mockDir(path.dirname(filePath));
66
+ export async function mockFile(filePath, fileMock) {
67
+ (await importMocked()).__mockFile(filePath, fileMock);
68
+ (await importMocked()).__mockDir(path.dirname(filePath));
68
69
  }
69
- export function mockCosmosConfig(cosmosConfigPath, cosmosConfig) {
70
+ export async function mockCosmosConfig(cosmosConfigPath, cosmosConfig) {
70
71
  const absPath = getCwdPath(cosmosConfigPath);
71
- mockFile(absPath, cosmosConfig);
72
+ await mockFile(absPath, cosmosConfig);
72
73
  }
73
- export function mockCwdModuleDefault(filePath, fileMock) {
74
+ export async function mockCwdModuleDefault(filePath, fileMock) {
74
75
  const absPath = getCwdPath(filePath);
75
- mockFile(absPath, { default: fileMock });
76
+ await mockFile(absPath, { default: fileMock });
76
77
  }
77
- export function resetFsMock() {
78
- requireMocked().__resetMock();
78
+ export async function resetFsMock() {
79
+ (await importMocked()).__resetMock();
79
80
  }
80
- function requireMocked() {
81
- return require('../utils/fs.js');
81
+ async function importMocked() {
82
+ return import('../utils/fs.js');
82
83
  }
@@ -1,2 +1,2 @@
1
- export declare function mockCliArgs(cliArgs: {}): void;
2
- export declare function unmockCliArgs(): void;
1
+ export declare function mockCliArgs(cliArgs: {}): Promise<void>;
2
+ export declare function unmockCliArgs(): Promise<void>;
@@ -1,6 +1,10 @@
1
+ import { vi } from 'vitest';
1
2
  // Secondary role of mocking yargs: Prevent Cosmos from intercepting the
2
- // --config arg passed to Jest
3
- jest.mock('yargs/yargs', () => {
3
+ // --config arg passed to Jest.
4
+ // Update: This doesn't seem to be the case with Vitest. The Vitest -c arg is
5
+ // not returned by yargs while running the tests, but I'll keep this commment
6
+ // in case this changes in the future.
7
+ vi.mock('yargs/yargs', () => {
4
8
  let argv = {};
5
9
  const yargs = () => ({
6
10
  boolean: () => yargs(),
@@ -9,14 +13,14 @@ jest.mock('yargs/yargs', () => {
9
13
  yargs.__mockArgsv = (newArgv) => {
10
14
  argv = newArgv;
11
15
  };
12
- return yargs;
16
+ return { default: yargs };
13
17
  });
14
- export function mockCliArgs(cliArgs) {
15
- requireMocked().__mockArgsv(cliArgs);
18
+ export async function mockCliArgs(cliArgs) {
19
+ (await importMocked()).default.__mockArgsv(cliArgs);
16
20
  }
17
- export function unmockCliArgs() {
18
- requireMocked().__mockArgsv({});
21
+ export async function unmockCliArgs() {
22
+ (await importMocked()).default.__mockArgsv({});
19
23
  }
20
- function requireMocked() {
21
- return require('yargs/yargs');
24
+ async function importMocked() {
25
+ return import('yargs/yargs');
22
26
  }
@@ -5,5 +5,5 @@ type FindUserModulePathsArgs = {
5
5
  fixtureFileSuffix: string;
6
6
  ignore: string[];
7
7
  };
8
- export declare function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: FindUserModulePathsArgs): UserModulePaths;
8
+ export declare function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: FindUserModulePathsArgs): Promise<UserModulePaths>;
9
9
  export {};
@@ -1,8 +1,8 @@
1
- import { globSync } from 'glob';
1
+ import { glob } from 'glob';
2
2
  import micromatch from 'micromatch';
3
3
  import { getDecoratorPatterns, getFixturePatterns, } from './shared.js';
4
- export function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
5
- const paths = globSync('**/*', {
4
+ export async function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
5
+ const paths = await glob('**/*', {
6
6
  cwd: rootDir,
7
7
  absolute: true,
8
8
  ignore,
@@ -1,2 +1 @@
1
- /// <reference types="node" />
2
1
  export declare function isNodeError(err: any): err is NodeJS.ErrnoException;
@@ -1,2 +1 @@
1
1
  export declare function requireModule(moduleId: string): any;
2
- export declare function requireFrom(fromDirectory: string, moduleId: string): any;
@@ -1,13 +1,5 @@
1
1
  import { createRequire } from 'node:module';
2
- import path from 'path';
3
- // NOTE: This is ESM code that can't run in Jest yet, which means that this
4
- // module always needs to be mocked in tests until Jest adds ESM support.
5
2
  export function requireModule(moduleId) {
6
3
  const require = createRequire(import.meta.url);
7
4
  return require(moduleId);
8
5
  }
9
- export function requireFrom(fromDirectory, moduleId) {
10
- // Inspired by https://github.com/sindresorhus/import-from
11
- const require = createRequire(path.resolve(fromDirectory, 'noop.js'));
12
- return require(moduleId);
13
- }
@@ -1,6 +1,4 @@
1
1
  import { createRequire } from 'node:module';
2
- // NOTE: This is ESM code that can't run in Jest yet, which means that this
3
- // module always needs to be mocked in tests until Jest adds ESM support.
4
2
  // One day this code will be replaced by import.meta.resolve
5
3
  // https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent
6
4
  // Still under --experimental-import-meta-resolve flag in Node v19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos",
3
- "version": "6.1.2-canary.fbe721b.0+fbe721b",
3
+ "version": "6.2.0",
4
4
  "description": "Sandbox for developing and testing UI components in isolation",
5
5
  "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos",
6
6
  "license": "MIT",
@@ -8,18 +8,18 @@
8
8
  "main": "./index.js",
9
9
  "dependencies": {
10
10
  "@skidding/launch-editor": "2.2.3",
11
- "chokidar": "3.5.3",
12
- "express": "4.18.2",
13
- "glob": "10.3.10",
11
+ "chokidar": "3.6.0",
12
+ "express": "4.19.2",
13
+ "glob": "10.4.5",
14
14
  "http-proxy-middleware": "2.0.6",
15
15
  "lodash-es": "4.17.21",
16
- "micromatch": "4.0.5",
17
- "open": "8.4.2",
16
+ "micromatch": "4.0.7",
17
+ "open": "10.1.0",
18
18
  "pem": "1.14.8",
19
- "react-cosmos-core": "6.1.2-canary.fbe721b.0+fbe721b",
20
- "react-cosmos-renderer": "6.1.2-canary.fbe721b.0+fbe721b",
21
- "react-cosmos-ui": "6.1.2-canary.fbe721b.0+fbe721b",
22
- "ws": "8.16.0",
19
+ "react-cosmos-core": "^6.2.0",
20
+ "react-cosmos-renderer": "^6.2.0",
21
+ "react-cosmos-ui": "^6.2.0",
22
+ "ws": "8.18.0",
23
23
  "yargs": "17.7.2"
24
24
  },
25
25
  "bin": {
@@ -27,5 +27,5 @@
27
27
  "cosmos-export": "./bin/cosmos-export.js",
28
28
  "cosmos-native": "./bin/cosmos-native.js"
29
29
  },
30
- "gitHead": "fbe721b177adcb666317b6d1f4e4890d85de269b"
30
+ "gitHead": "965bf0e13230324699560be6eabb642c51c6d945"
31
31
  }
package/vitest.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/vitest.js';
package/vitest.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/vitest.js';
@@ -1,2 +0,0 @@
1
- export declare function requireModule(moduleId: string): any;
2
- export declare function requireFrom(fromDirectory: string, moduleId: string): any;
@@ -1,7 +0,0 @@
1
- // CJS mock for packages/react-cosmos/src/utils/requireModule.ts
2
- export function requireModule(moduleId) {
3
- return require(moduleId);
4
- }
5
- export function requireFrom(fromDirectory, moduleId) {
6
- return require(require.resolve(moduleId, { paths: [fromDirectory] }));
7
- }
@@ -1,2 +0,0 @@
1
- export declare function resolve(moduleId: string): string;
2
- export declare function resolveFrom(fromDirectory: string, moduleId: string): string;
@@ -1,7 +0,0 @@
1
- // CJS mock for packages/react-cosmos/src/utils/resolve.ts
2
- export function resolve(moduleId) {
3
- return require.resolve(moduleId);
4
- }
5
- export function resolveFrom(fromDirectory, moduleId) {
6
- return require.resolve(moduleId, { paths: [fromDirectory] });
7
- }
@@ -1 +0,0 @@
1
- export declare function getStaticPath(relPath: string): string;
@@ -1,4 +0,0 @@
1
- // CJS mock for packages/react-cosmos/src/shared/staticPath.ts
2
- export function getStaticPath(relPath) {
3
- return require.resolve(`../static/${relPath}`);
4
- }
@@ -1 +0,0 @@
1
- export declare function requireFromSilent(fromDirectory: string, moduleId: string): any;
@@ -1,11 +0,0 @@
1
- import { isNodeError } from './isNodeError.js';
2
- import { requireFrom } from './requireModule.js';
3
- export function requireFromSilent(fromDirectory, moduleId) {
4
- try {
5
- return requireFrom(fromDirectory, moduleId);
6
- }
7
- catch (err) {
8
- if (!isNodeError(err) || err.code !== 'MODULE_NOT_FOUND')
9
- console.log(err);
10
- }
11
- }
package/jest.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/jest.js';
package/jest.js DELETED
@@ -1 +0,0 @@
1
- export * from './dist/jest.js';
File without changes
File without changes