Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Replace getUploadUrls with uploadBuild mutation" #883

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 34 additions & 61 deletions node-src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,14 @@ vi.mock('node-fetch', () => ({
}

if (query?.match('PublishBuildMutation')) {
publishedBuild = {
id: variables.id,
...variables.input,
storybookUrl: 'https://5d67dc0374b2e300209c41e7-pfkaemtlit.chromatic.com/',
};
if (variables.input.isolatorUrl.startsWith('http://throw-an-error')) {
throw new Error('fetch error');
}
publishedBuild = { id: variables.id, ...variables.input };
return {
data: {
publishBuild: {
status: 'PUBLISHED',
storybookUrl: 'https://5d67dc0374b2e300209c41e7-pfkaemtlit.chromatic.com/',
},
},
};
Expand All @@ -134,8 +132,8 @@ vi.mock('node-fetch', () => ({
status: 'IN_PROGRESS',
specCount: 1,
componentCount: 1,
storybookUrl: 'https://5d67dc0374b2e300209c41e7-pfkaemtlit.chromatic.com/',
webUrl: 'http://test.com',
cachedUrl: 'https://5d67dc0374b2e300209c41e7-pfkaemtlit.chromatic.com/iframe.html',
...mockBuildFeatures,
app: {
account: {
Expand Down Expand Up @@ -195,8 +193,7 @@ vi.mock('node-fetch', () => ({
};
}

if (query?.match('UploadBuildMutation') || query?.match('UploadMetadataMutation')) {
const key = query?.match('UploadBuildMutation') ? 'uploadBuild' : 'uploadMetadata';
if (query?.match('GetUploadUrlsMutation')) {
const contentTypes = {
html: 'text/html',
js: 'text/javascript',
Expand All @@ -205,17 +202,13 @@ vi.mock('node-fetch', () => ({
};
return {
data: {
[key]: {
info: {
targets: variables.files.map(({ filePath }) => ({
contentType: contentTypes[filePath.split('.').at(-1)],
fileKey: '',
filePath,
formAction: 'https://s3.amazonaws.com',
formFields: {},
})),
},
userErrors: [],
getUploadUrls: {
domain: 'https://chromatic.com',
urls: variables.paths.map((path: string) => ({
path,
url: `https://cdn.example.com/${path}`,
contentType: contentTypes[path.split('.').at(-1)],
})),
},
},
};
Expand Down Expand Up @@ -412,7 +405,7 @@ it('runs in simple situations', async () => {
storybookViewLayer: 'viewLayer',
committerEmail: '[email protected]',
committerName: 'tester',
storybookUrl: 'https://5d67dc0374b2e300209c41e7-pfkaemtlit.chromatic.com/',
isolatorUrl: `https://chromatic.com/iframe.html`,
});
});

Expand Down Expand Up @@ -469,24 +462,20 @@ it('calls out to npm build script passed and uploads files', async () => {
expect.any(Object),
[
{
contentHash: 'hash',
contentLength: 42,
contentType: 'text/html',
fileKey: '',
filePath: 'iframe.html',
formAction: 'https://s3.amazonaws.com',
formFields: {},
localPath: expect.stringMatching(/\/iframe\.html$/),
targetPath: 'iframe.html',
targetUrl: 'https://cdn.example.com/iframe.html',
},
{
contentHash: 'hash',
contentLength: 42,
contentType: 'text/html',
fileKey: '',
filePath: 'index.html',
formAction: 'https://s3.amazonaws.com',
formFields: {},
localPath: expect.stringMatching(/\/index\.html$/),
targetPath: 'index.html',
targetUrl: 'https://cdn.example.com/index.html',
},
],
expect.any(Function)
Expand All @@ -502,24 +491,20 @@ it('skips building and uploads directly with storybook-build-dir', async () => {
expect.any(Object),
[
{
contentHash: 'hash',
contentLength: 42,
contentType: 'text/html',
fileKey: '',
filePath: 'iframe.html',
formAction: 'https://s3.amazonaws.com',
formFields: {},
localPath: expect.stringMatching(/\/iframe\.html$/),
targetPath: 'iframe.html',
targetUrl: 'https://cdn.example.com/iframe.html',
},
{
contentHash: 'hash',
contentLength: 42,
contentType: 'text/html',
fileKey: '',
filePath: 'index.html',
formAction: 'https://s3.amazonaws.com',
formFields: {},
localPath: expect.stringMatching(/\/index\.html$/),
targetPath: 'index.html',
targetUrl: 'https://cdn.example.com/index.html',
},
],
expect.any(Function)
Expand Down Expand Up @@ -714,44 +699,32 @@ it('should upload metadata files if --upload-metadata is passed', async () => {
expect(upload.mock.calls.at(-1)[1]).toEqual(
expect.arrayContaining([
{
contentLength: 518,
contentType: 'text/javascript',
fileKey: '',
filePath: '.chromatic/main.js',
formAction: 'https://s3.amazonaws.com',
formFields: {},
localPath: '.storybook/main.js',
targetPath: '.chromatic/main.js',
contentLength: 518,
contentType: 'text/javascript',
targetUrl: 'https://cdn.example.com/.chromatic/main.js',
},
{
contentLength: 457,
contentType: 'application/json',
fileKey: '',
filePath: '.chromatic/preview-stats.trimmed.json',
formAction: 'https://s3.amazonaws.com',
formFields: {},
localPath: 'storybook-out/preview-stats.trimmed.json',
targetPath: '.chromatic/preview-stats.trimmed.json',
contentLength: 457,
contentType: 'application/json',
targetUrl: 'https://cdn.example.com/.chromatic/preview-stats.trimmed.json',
},
{
contentLength: 1338,
contentType: 'text/javascript',
fileKey: '',
filePath: '.chromatic/preview.js',
formAction: 'https://s3.amazonaws.com',
formFields: {},
localPath: '.storybook/preview.js',
targetPath: '.chromatic/preview.js',
contentLength: 1338,
contentType: 'text/javascript',
targetUrl: 'https://cdn.example.com/.chromatic/preview.js',
},
{
contentLength: expect.any(Number),
contentType: 'text/html',
fileKey: '',
filePath: '.chromatic/index.html',
formAction: 'https://s3.amazonaws.com',
formFields: {},
localPath: expect.any(String),
targetPath: '.chromatic/index.html',
contentLength: expect.any(Number),
contentType: 'text/html',
targetUrl: 'https://cdn.example.com/.chromatic/index.html',
},
])
);
Expand Down
2 changes: 1 addition & 1 deletion node-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export async function run({
code: ctx.exitCode,
url: ctx.build?.webUrl,
buildUrl: ctx.build?.webUrl,
storybookUrl: ctx.build?.storybookUrl,
storybookUrl: ctx.build?.cachedUrl?.replace(/iframe\.html.*$/, ''),
specCount: ctx.build?.specCount,
componentCount: ctx.build?.componentCount,
testCount: ctx.build?.testCount,
Expand Down
2 changes: 1 addition & 1 deletion node-src/lib/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async function makeZipFile(ctx: Context, files: FileDesc[]) {
archive.pipe(sink);

files.forEach(({ localPath, targetPath: name }) => {
ctx.log.debug(`Adding to zip archive: ${name}`);
ctx.log.debug({ name }, 'Adding file to zip archive');
archive.append(createReadStream(localPath), { name });
});

Expand Down
Loading
Loading