-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v5-candidate' into feature/add-series-tree-shakable
- Loading branch information
Showing
10 changed files
with
324 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
|
||
import { generatePageContent } from './generate-test-cases'; | ||
import { getTestCases, TestCase } from './helpers/get-test-cases'; | ||
import { rmRf } from './utils'; | ||
|
||
if (process.argv.length < 3) { | ||
console.log( | ||
'Usage: generate-golden-content GOLDEN_OUTPUT_PATH' | ||
); | ||
process.exit(1); | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
const goldenOutputPath = args[0]; | ||
|
||
const buildMode = | ||
process.env.PRODUCTION_BUILD === 'true' ? 'production' : 'development'; | ||
|
||
const testCases = getTestCases(); | ||
|
||
rmRf(goldenOutputPath); | ||
fs.mkdirSync(goldenOutputPath, { recursive: true }); | ||
|
||
for (const groupName of Object.keys(testCases)) { | ||
generateTestCases(testCases[groupName]); | ||
} | ||
|
||
function generateTestCases(groupTestCases: TestCase[]): void { | ||
for (const testCase of groupTestCases) { | ||
const testCaseOutDir = path.join(goldenOutputPath, testCase.name); | ||
rmRf(testCaseOutDir); | ||
fs.mkdirSync(testCaseOutDir, { recursive: true }); | ||
path.join(testCaseOutDir, 'test-content.html'); | ||
|
||
const goldenPageContent = generatePageContent( | ||
'', | ||
testCase.caseContent, | ||
buildMode | ||
); | ||
|
||
fs.writeFileSync( | ||
path.join(testCaseOutDir, 'test-content.html'), | ||
goldenPageContent | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
const currentFilePath = fileURLToPath(import.meta.url); | ||
const currentDirectory = path.dirname(currentFilePath); | ||
|
||
const dummyContent = fs.readFileSync( | ||
path.join(currentDirectory, 'helpers', 'test-page-dummy.html'), | ||
{ encoding: 'utf-8' } | ||
); | ||
const resizeObserverPolyfill = | ||
fs | ||
.readFileSync( | ||
path.join( | ||
currentDirectory, | ||
...'../../../node_modules/@juggle/resize-observer/lib/exports/resize-observer.umd.js'.split( | ||
'/' | ||
) | ||
), | ||
{ encoding: 'utf-8' } | ||
) | ||
.replace(/global\.ResizeObserver/g, 'global.ResizeObserverPolyfill') + | ||
'; window.ResizeObserver = window.ResizeObserverPolyfill.ResizeObserver'; | ||
|
||
export function generatePageContent( | ||
standaloneBundlePath: string, | ||
testCaseCode: string, | ||
buildMode: 'production' | 'development' | ||
): string { | ||
return dummyContent | ||
.replace('//RESIZE_OBSERVER_POLYFILL', resizeObserverPolyfill) | ||
.replace('PATH_TO_STANDALONE_MODULE', standaloneBundlePath || 'PATH_TO_STANDALONE_MODULE') // keep string if using BRANCH_SPECIFIC_TEST | ||
.replace('TEST_CASE_SCRIPT', testCaseCode) | ||
.replace('{BUILD_MODE}', buildMode); | ||
} |
Oops, something went wrong.