react-cosmos 6.1.1 → 6.1.2-canary.15db638.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 (50) hide show
  1. package/README.md +2 -2
  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.d.ts +11 -0
  6. package/dist/corePlugins/fixturesJsonPlugin.js +50 -0
  7. package/dist/corePlugins/index.js +4 -2
  8. package/dist/cosmosConfig/types.d.ts +2 -4
  9. package/dist/cosmosPlugin/types.d.ts +0 -1
  10. package/dist/devServer/httpServer.d.ts +0 -2
  11. package/dist/devServer/messageHandler.d.ts +0 -1
  12. package/dist/getFixtures/getFixtures.d.ts +1 -1
  13. package/dist/getFixtures/getFixtures.js +6 -5
  14. package/dist/getFixtures/importUserModules.d.ts +1 -1
  15. package/dist/getFixtures/importUserModules.js +10 -14
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +0 -1
  18. package/dist/shared/playgroundHtml.js +2 -2
  19. package/dist/shared/serverFixtureList.d.ts +1 -1
  20. package/dist/shared/serverFixtureList.js +2 -2
  21. package/dist/shared/staticPath.js +9 -2
  22. package/dist/testHelpers/mockConsole.js +2 -1
  23. package/dist/testHelpers/mockFetch.d.ts +2 -2
  24. package/dist/testHelpers/mockFetch.js +2 -1
  25. package/dist/testHelpers/mockFs.d.ts +4 -4
  26. package/dist/testHelpers/mockFs.js +14 -13
  27. package/dist/testHelpers/mockYargs.d.ts +2 -2
  28. package/dist/testHelpers/mockYargs.js +13 -9
  29. package/dist/userModules/findUserModulePaths.d.ts +1 -1
  30. package/dist/userModules/findUserModulePaths.js +3 -3
  31. package/dist/userModules/shared.js +3 -0
  32. package/dist/utils/isNodeError.d.ts +0 -1
  33. package/dist/utils/requireModule.d.ts +0 -1
  34. package/dist/utils/requireModule.js +0 -8
  35. package/dist/utils/resolve.js +0 -2
  36. package/package.json +11 -11
  37. package/vitest.d.ts +1 -0
  38. package/vitest.js +1 -0
  39. package/dist/cjsMocks/requireModule.d.ts +0 -2
  40. package/dist/cjsMocks/requireModule.js +0 -7
  41. package/dist/cjsMocks/resolve.d.ts +0 -2
  42. package/dist/cjsMocks/resolve.js +0 -7
  43. package/dist/cjsMocks/staticPath.d.ts +0 -1
  44. package/dist/cjsMocks/staticPath.js +0 -4
  45. package/dist/utils/requireSilent.d.ts +0 -1
  46. package/dist/utils/requireSilent.js +0 -11
  47. package/jest.d.ts +0 -1
  48. package/jest.js +0 -1
  49. /package/dist/{jest.d.ts → vitest.d.ts} +0 -0
  50. /package/dist/{jest.js → vitest.js} +0 -0
package/README.md CHANGED
@@ -26,11 +26,11 @@ To chat with other community members you can join the [React Cosmos Discord](htt
26
26
 
27
27
  You can also ask questions, voice ideas, and share your projects on [GitHub Discussions](https://github.com/react-cosmos/react-cosmos/discussions).
28
28
 
29
- Our [Code of Conduct](/CODE_OF_CONDUCT.md) applies to all React Cosmos community channels.
29
+ Our [Code of Conduct](/.github/CODE_OF_CONDUCT.md) applies to all React Cosmos community channels.
30
30
 
31
31
  ## Contributing
32
32
 
33
- Please see our [CONTRIBUTING.md](/CONTRIBUTING.md).
33
+ Please see our [CONTRIBUTING.md](/.github/CONTRIBUTING.md).
34
34
 
35
35
  [Become a Sponsor](https://github.com/sponsors/ovidiuch) to support the ongoing development of React Cosmos.
36
36
 
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
  },
@@ -0,0 +1,11 @@
1
+ import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
+ export type CosmosFixtureJson = {
3
+ filePath: string;
4
+ cleanPath: string[];
5
+ rendererUrl: string;
6
+ };
7
+ export type CosmosFixturesJson = {
8
+ rendererUrl: string | null;
9
+ fixtures: CosmosFixtureJson[];
10
+ };
11
+ export declare const fixturesJsonPlugin: CosmosServerPlugin;
@@ -0,0 +1,50 @@
1
+ import { sortBy } from 'lodash-es';
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { createRendererUrl, pickRendererUrl, removeFixtureNameExtension, removeFixtureNameSuffix, } from 'react-cosmos-core';
5
+ import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
6
+ import { importKeyPath } from '../userModules/shared.js';
7
+ export const fixturesJsonPlugin = {
8
+ name: 'fixturesJson',
9
+ devServer({ cosmosConfig, expressApp }) {
10
+ expressApp.get('/cosmos.fixtures.json', async (req, res) => {
11
+ res.json(await createFixtureItems(cosmosConfig, 'dev'));
12
+ });
13
+ },
14
+ async export({ cosmosConfig }) {
15
+ const { exportPath } = cosmosConfig;
16
+ const json = await createFixtureItems(cosmosConfig, 'export');
17
+ await fs.writeFile(path.join(exportPath, 'cosmos.fixtures.json'), JSON.stringify(json, null, 2));
18
+ },
19
+ };
20
+ async function createFixtureItems(cosmosConfig, command) {
21
+ const rendererUrl = pickRendererUrl(cosmosConfig.rendererUrl, command);
22
+ if (!rendererUrl) {
23
+ return {
24
+ rendererUrl: null,
25
+ fixtures: [],
26
+ };
27
+ }
28
+ const { fixturesDir, fixtureFileSuffix } = 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
+ });
39
+ return {
40
+ rendererUrl,
41
+ fixtures: sortBy(fixtures, f => f.cleanPath.join('-')),
42
+ };
43
+ }
44
+ function cleanFixturePath(filePath, fixturesDir, fixtureSuffix) {
45
+ const paths = filePath.split('/').filter(p => p !== fixturesDir);
46
+ return [
47
+ ...paths.slice(0, -1),
48
+ removeFixtureNameSuffix(removeFixtureNameExtension(paths[paths.length - 1]), fixtureSuffix),
49
+ ];
50
+ }
@@ -1,15 +1,17 @@
1
1
  import { fixtureWatcherPlugin } from './fixtureWatcherPlugin.js';
2
+ import { fixturesJsonPlugin } from './fixturesJsonPlugin.js';
2
3
  import { httpProxyPlugin } from './httpProxyPlugin.js';
3
4
  import { openFilePlugin } from './openFilePlugin.js';
4
5
  import { pluginEndpointPlugin } from './pluginEndpointPlugin.js';
5
6
  import { portRetryPlugin } from './portRetryPlugin.js';
6
7
  export const coreServerPlugins = [
7
8
  portRetryPlugin,
9
+ fixturesJsonPlugin,
8
10
  httpProxyPlugin,
9
11
  openFilePlugin,
10
12
  pluginEndpointPlugin,
11
13
  ];
12
- // Omit starting chokidar in Jest tests for performance reasons
13
- 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) {
14
16
  coreServerPlugins.push(fixtureWatcherPlugin);
15
17
  }
@@ -1,3 +1,4 @@
1
+ import { CosmosRendererUrl } from 'react-cosmos-core';
1
2
  interface HttpsOptions {
2
3
  keyPath: string;
3
4
  certPath: string;
@@ -23,10 +24,7 @@ export type CosmosConfig = {
23
24
  portRetries: number;
24
25
  plugins: string[];
25
26
  publicUrl: string;
26
- rendererUrl: null | string | {
27
- dev: string;
28
- export: string;
29
- };
27
+ rendererUrl: CosmosRendererUrl;
30
28
  rootDir: string;
31
29
  staticPath: null | string;
32
30
  watchDirs: string[];
@@ -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);
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,26 +1,22 @@
1
- import path from 'path';
2
1
  import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
3
- import { slash } from '../utils/slash.js';
4
- export function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
5
- const { fixturePaths, decoratorPaths } = findUserModulePaths({
2
+ import { importKeyPath } from '../userModules/shared.js';
3
+ export async function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
4
+ const { fixturePaths, decoratorPaths } = await findUserModulePaths({
6
5
  rootDir,
7
6
  fixturesDir,
8
7
  fixtureFileSuffix,
9
8
  ignore,
10
9
  });
11
10
  return {
12
- fixtures: importModules(fixturePaths, rootDir),
13
- decorators: importModules(decoratorPaths, rootDir),
11
+ fixtures: await importModules(fixturePaths, rootDir),
12
+ decorators: await importModules(decoratorPaths, rootDir),
14
13
  };
15
14
  }
16
- function importModules(paths, rootDir) {
17
- const modules = paths.map(p => {
18
- // Converting to forward slashes on Windows is important because the
19
- // slashes are used for generating a sorted list of fixtures and
20
- // decorators.
21
- const relPath = slash(path.relative(rootDir, p));
22
- return { relPath, module: require(p) };
23
- });
15
+ async function importModules(paths, rootDir) {
16
+ const modules = await Promise.all(paths.map(async (p) => {
17
+ const relPath = importKeyPath(p, rootDir);
18
+ return { relPath, module: await import(p) };
19
+ }));
24
20
  return modules.reduce((acc, { relPath, module }) => ({
25
21
  ...acc,
26
22
  [relPath]: module,
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { CosmosFixtureJson, CosmosFixturesJson, } from './corePlugins/fixturesJsonPlugin.js';
1
2
  export * from './cosmosConfig/createCosmosConfig.js';
2
3
  export * from './cosmosConfig/detectCosmosConfig.js';
3
4
  export * from './cosmosConfig/getCosmosConfigAtPath.js';
@@ -15,7 +16,6 @@ export * from './userModules/fixtureWatcher.js';
15
16
  export * from './userModules/generateUserImports.js';
16
17
  export * from './utils/cli.js';
17
18
  export * from './utils/fs.js';
18
- export * from './utils/requireSilent.js';
19
19
  export * from './utils/resolve.js';
20
20
  export * from './utils/resolveLoose.js';
21
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,
@@ -23,6 +23,9 @@ export function createImportMap(paths, rootDir, relativeToDir) {
23
23
  }), {});
24
24
  }
25
25
  export function importKeyPath(filePath, rootDir) {
26
+ // Converting to forward slashes on Windows is important because the
27
+ // slashes are used for generating a sorted list of fixtures and
28
+ // decorators.
26
29
  return slash(path.relative(rootDir, filePath));
27
30
  }
28
31
  export function importPath(filePath, relativeToDir) {
@@ -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.1",
3
+ "version": "6.1.2-canary.15db638.0+15db638",
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.1",
20
- "react-cosmos-renderer": "^6.1.1",
21
- "react-cosmos-ui": "^6.1.1",
22
- "ws": "8.16.0",
19
+ "react-cosmos-core": "6.1.2-canary.15db638.0+15db638",
20
+ "react-cosmos-renderer": "6.1.2-canary.15db638.0+15db638",
21
+ "react-cosmos-ui": "6.1.2-canary.15db638.0+15db638",
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": "f83799a26584a3f34914ce4ebf5c427df1df3c25"
30
+ "gitHead": "15db6389056d322dd3df5012262cfd620867e49b"
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