-
Notifications
You must be signed in to change notification settings - Fork 939
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: setup formbricks/js e2e tests #1794
feat: setup formbricks/js e2e tests #1794
Conversation
The latest updates on your projects. Learn more about Vercel for Git 鈫楋笌 |
Thank you for following the naming conventions for pull request titles! 馃檹 |
apps/web/playwright/utils/helper.tsThe current method of replacing the environment ID in the HTML file involves reading the entire file into memory, performing the replacement, and then writing the entire file back to disk. This can be inefficient for large files. A more efficient method would be to use a stream-based approach to read, modify, and write the file in chunks. // In helper.ts
import { createReadStream, createWriteStream } from 'fs';
import { Transform } from 'stream';
export const replaceEnvironmentIdInHtml = (filePath: string, environmentId: string): string => {
const readStream = createReadStream(filePath, 'utf-8');
const writeStream = createWriteStream(filePath);
const transformStream = new Transform({
transform(chunk, encoding, callback) {
const replacedChunk = chunk.toString().replace(/environmentId: ".*?"/, `environmentId: "${environmentId}"`);
callback(null, replacedChunk);
}
});
readStream.pipe(transformStream).pipe(writeStream);
return "file:///" + filePath;
};
|
export const replaceEnvironmentIdInHtml = (filePath: string, environmentId: string): string => { | ||
let htmlContent = readFileSync(filePath, "utf-8"); | ||
htmlContent = htmlContent.replace(/environmentId: ".*?"/, `environmentId: "${environmentId}"`); | ||
|
||
writeFileSync(filePath, htmlContent); | ||
return "file:///" + filePath; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current method of replacing the environment ID in the HTML file involves reading the entire file into memory, performing the replacement, and then writing the entire file back to disk. This can be inefficient for large files. A more efficient method would be to use a stream-based approach to read, modify, and write the file in chunks.
export const replaceEnvironmentIdInHtml = (filePath: string, environmentId: string): string => { | |
let htmlContent = readFileSync(filePath, "utf-8"); | |
htmlContent = htmlContent.replace(/environmentId: ".*?"/, `environmentId: "${environmentId}"`); | |
writeFileSync(filePath, htmlContent); | |
return "file:///" + filePath; | |
}; | |
import { createReadStream, createWriteStream } from 'fs'; | |
import { Transform } from 'stream'; | |
export const replaceEnvironmentIdInHtml = (filePath: string, environmentId: string): string => { | |
const readStream = createReadStream(filePath, 'utf-8'); | |
const writeStream = createWriteStream(filePath); | |
const transformStream = new Transform({ | |
transform(chunk, encoding, callback) { | |
const replacedChunk = chunk.toString().replace(/environmentId: ".*?"/, `environmentId: "${environmentId}"`); | |
callback(null, replacedChunk); | |
} | |
}); | |
readStream.pipe(transformStream).pipe(writeStream); | |
return "file:///" + filePath; | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ShubhamPalriwala thank you for the new test; looks great! 馃槉馃挭
What does this PR do?
E2E tests for
Also adds a step in CI to build the local JS package
Also uses the native HTML file to keep things light in the CI!
Fixes # (issue)
Type of change
How should this be tested?
Checklist
Required
pnpm build
console.logs
git pull origin main
Appreciated