Skip to content

Commit

Permalink
feat(workspace-plugin): move test-ssr task to /stories project to cre…
Browse files Browse the repository at this point in the history
…ate proper dependency tree
  • Loading branch information
Hotell committed May 22, 2024
1 parent 8cda771 commit 4260ec0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ describe('react-library generator', () => {
mainEntryPointFilePath:
'<projectRoot>/../../../../../../dist/out-tsc/types/packages/react-components/<unscopedPackageName>/library/src/index.d.ts',
});
expect(readJson(tree, `${library.root}/package.json`)).toEqual(
const libPackageJson = readJson(tree, `${library.root}/package.json`);
expect(libPackageJson.scripts['test-ssr']).toEqual(undefined);
expect(libPackageJson).toEqual(
expect.objectContaining({
name: '@proj/react-one-preview',
private: true,
Expand Down Expand Up @@ -197,6 +199,7 @@ describe('react-library generator', () => {
start: 'yarn storybook',
storybook: 'start-storybook',
'type-check': 'just-scripts type-check',
'test-ssr': 'test-ssr "./src/**/*.stories.tsx"',
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ describe('split-library-in-two generator', () => {
}),
);

expect(readJson(tree, `${newConfig.root}/package.json`)).toEqual(
const newConfigPackageJSON = readJson(tree, `${newConfig.root}/package.json`);
expect(newConfigPackageJSON.scripts['test-ssr']).toEqual(undefined);
expect(newConfigPackageJSON).toEqual(
expect.objectContaining({
name: '@proj/react-hello',
scripts: expect.objectContaining({
'test-ssr': 'test-ssr "../stories/src/**/*.stories.tsx"',
'type-check': 'just-scripts type-check',
storybook: 'yarn --cwd ../stories storybook',
}),
Expand Down Expand Up @@ -192,6 +193,7 @@ describe('split-library-in-two generator', () => {
"lint": "eslint src/",
"start": "yarn storybook",
"storybook": "start-storybook",
"test-ssr": "test-ssr \\"./src/**/*.stories.tsx\\"",
"type-check": "just-scripts type-check",
},
"version": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ interface Options extends SplitLibraryInTwoGeneratorSchema {
projectOffsetFromRoot: { old: string; updated: string };
oldContent: {
tsConfig: Record<string, unknown>;
packageJSON: Record<string, unknown>;
};

oldPackageMetadata: {
ssrTestsScript: string | undefined;
};
}

Expand Down Expand Up @@ -113,6 +118,7 @@ function splitLibraryInTwoInternal(
return;
}

const packageJSON = readJson(tree, joinPathFragments(projectConfig.root, 'package.json'));
const normalizedOptions = {
projectName,
projectConfig,
Expand All @@ -122,6 +128,10 @@ function splitLibraryInTwoInternal(
},
oldContent: {
tsConfig: readJson(tree, joinPathFragments(projectConfig.root, 'tsconfig.json')),
packageJSON,
},
oldPackageMetadata: {
ssrTestsScript: packageJSON?.scripts?.['test-ssr'],
},
};

Expand Down Expand Up @@ -184,9 +194,7 @@ function makeSrcLibrary(tree: Tree, options: Options, logger: typeof output) {
json.scripts ??= {};
json.scripts.storybook = 'yarn --cwd ../stories storybook';
json.scripts['type-check'] = 'just-scripts type-check';
if (json.scripts['test-ssr']) {
json.scripts['test-ssr'] = `test-ssr \"../stories/src/**/*.stories.tsx\"`;
}
delete json.scripts['test-ssr'];

const deps = getMissingDevDependenciesFromCypressAndJestFiles(
tree,
Expand Down Expand Up @@ -315,6 +323,7 @@ function makeStoriesLibrary(tree: Tree, options: Options, logger: typeof output)
'type-check': 'just-scripts type-check',
lint: 'eslint src/',
format: 'just-scripts prettier',
...(options.oldPackageMetadata.ssrTestsScript ? { 'test-ssr': `test-ssr "./src/**/*.stories.tsx"` } : null),
},
devDependencies: {
...storiesWorkspaceDeps,
Expand Down

0 comments on commit 4260ec0

Please sign in to comment.