Skip to content

Commit

Permalink
Merge pull request #1028 from chromaui/jmhobbs/cap-1581-refuse-to-upl…
Browse files Browse the repository at this point in the history
…oad-chromatic

Don't upload files from `.chromatic` directory
  • Loading branch information
jmhobbs authored Sep 10, 2024
2 parents 5f0500f + 69e24e0 commit 049eebf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions node-src/tasks/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,35 @@ describe('validateFiles', () => {
await expect(validateFiles(ctx)).rejects.toThrow('Invalid Storybook build at /static/');
});

it("does not include the .chromatic directory in the file list", async () => {
readdirSyncMock.mockImplementation((path) => {
if(path === ".chromatic") {
return ['zip-unpacked.txt'] as any
}
return ['iframe.html', 'index.html', '.chromatic'] as any
});
statSyncMock.mockImplementation((path) => {
if(path === ".chromatic") {
return { isDirectory: () => true, size: 42 } as any
}
return { isDirectory: () => false, size: 42 } as any
});

const ctx = { env, log, http, sourceDir: '.' } as any;
await validateFiles(ctx);

expect(ctx.fileInfo).toEqual(
expect.objectContaining({
lengths: [
{ contentLength: 42, knownAs: 'iframe.html', pathname: 'iframe.html' },
{ contentLength: 42, knownAs: 'index.html', pathname: 'index.html' },
],
paths: ['iframe.html', 'index.html'],
total: 84,
})
);
});

describe('with buildLogFile', () => {
it('retries using outputDir from build-storybook.log', async () => {
readdirSyncMock.mockReturnValueOnce([]);
Expand Down
5 changes: 5 additions & 0 deletions node-src/tasks/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const SPECIAL_CHARS_REGEXP = /([$^*+?()[\]])/g;
// We don't want the paths to include rootDir -- so if rootDir = storybook-static,
// paths will be like iframe.html rather than storybook-static/iframe.html
function getPathsInDir(ctx: Context, rootDir: string, dirname = '.'): PathSpec[] {
// .chromatic is a special directory reserved for internal use and should not be uploaded
if (dirname === '.chromatic') {
return [];
}

try {
return readdirSync(join(rootDir, dirname)).flatMap((p: string) => {
const pathname = join(dirname, p);
Expand Down

0 comments on commit 049eebf

Please sign in to comment.