From cbbe794f6dd603d41e69806c8b80a1bb84dd2571 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Tue, 20 Feb 2024 15:56:27 +0100 Subject: [PATCH 1/2] [TS migration] Migrate 'writeTestStats.js' test to TypeScript --- .../{writeTestStats.js => writeTestStats.ts} | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) rename tests/e2e/measure/{writeTestStats.js => writeTestStats.ts} (57%) diff --git a/tests/e2e/measure/writeTestStats.js b/tests/e2e/measure/writeTestStats.ts similarity index 57% rename from tests/e2e/measure/writeTestStats.js rename to tests/e2e/measure/writeTestStats.ts index 6de9dcc79db4..f2e0adfa0b9d 100644 --- a/tests/e2e/measure/writeTestStats.js +++ b/tests/e2e/measure/writeTestStats.ts @@ -1,18 +1,28 @@ import fs from 'fs'; import config from '../config'; +type Stats = { + /** The name for the test, used in outputs. */ + name: string; + + /** The average time for the test to run. */ + mean: number; + + /** The standard deviation of the test. */ + stdev: number; + + /** The data points */ + entries: number[]; + + /** The number of times the test was run. */ + runs: number; +}; + /** * Writes the results of `getStats` to the {@link OUTPUT_FILE_CURRENT} file. - * - * @param {Object} stats - * @param {string} stats.name - The name for the test, used in outputs. - * @param {number} stats.mean - The average time for the test to run. - * @param {number} stats.stdev - The standard deviation of the test. - * @param {number} stats.entries - The data points - * @param {number} stats.runs - The number of times the test was run. - * @param {string} [path] - The path to write to. Defaults to {@link OUTPUT_FILE_CURRENT}. + * @param [path] - The path to write to. Defaults to {@link OUTPUT_FILE_CURRENT}. */ -export default (stats, path = config.OUTPUT_FILE_CURRENT) => { +function writeTestStats(stats: Stats, path = config.OUTPUT_FILE_CURRENT) { if (!stats.name || stats.mean == null || stats.stdev == null || !stats.entries || !stats.runs) { throw new Error(`Invalid stats object:\n${JSON.stringify(stats, null, 2)}\n\n`); } @@ -29,4 +39,6 @@ export default (stats, path = config.OUTPUT_FILE_CURRENT) => { console.error(`Error writing ${path}`, error); throw error; } -}; +} + +export default writeTestStats; From 2097550fe02ce360fcacee623239895f5eabe642 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Thu, 22 Feb 2024 08:30:13 +0100 Subject: [PATCH 2/2] Remove file instead --- tests/e2e/measure/writeTestStats.ts | 44 ----------------------------- 1 file changed, 44 deletions(-) delete mode 100644 tests/e2e/measure/writeTestStats.ts diff --git a/tests/e2e/measure/writeTestStats.ts b/tests/e2e/measure/writeTestStats.ts deleted file mode 100644 index f2e0adfa0b9d..000000000000 --- a/tests/e2e/measure/writeTestStats.ts +++ /dev/null @@ -1,44 +0,0 @@ -import fs from 'fs'; -import config from '../config'; - -type Stats = { - /** The name for the test, used in outputs. */ - name: string; - - /** The average time for the test to run. */ - mean: number; - - /** The standard deviation of the test. */ - stdev: number; - - /** The data points */ - entries: number[]; - - /** The number of times the test was run. */ - runs: number; -}; - -/** - * Writes the results of `getStats` to the {@link OUTPUT_FILE_CURRENT} file. - * @param [path] - The path to write to. Defaults to {@link OUTPUT_FILE_CURRENT}. - */ -function writeTestStats(stats: Stats, path = config.OUTPUT_FILE_CURRENT) { - if (!stats.name || stats.mean == null || stats.stdev == null || !stats.entries || !stats.runs) { - throw new Error(`Invalid stats object:\n${JSON.stringify(stats, null, 2)}\n\n`); - } - - if (!fs.existsSync(path)) { - fs.writeFileSync(path, '[]'); - } - - try { - const content = JSON.parse(fs.readFileSync(path, 'utf8')); - const line = `${JSON.stringify(content.concat([stats]))}\n`; - fs.writeFileSync(path, line); - } catch (error) { - console.error(`Error writing ${path}`, error); - throw error; - } -} - -export default writeTestStats;