From 49638c6c7129d425b49ed0b3de15f8f7f959a4b4 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Wed, 30 Sep 2020 22:21:40 +0300 Subject: [PATCH] Regression tests for stats and ZWO creation --- src/test/__snapshots__/cli.test.ts.snap | 246 ++++++++++++++++++++++++ src/test/cli.test.ts | 30 +++ 2 files changed, 276 insertions(+) create mode 100644 src/test/__snapshots__/cli.test.ts.snap create mode 100644 src/test/cli.test.ts diff --git a/src/test/__snapshots__/cli.test.ts.snap b/src/test/__snapshots__/cli.test.ts.snap new file mode 100644 index 0000000..54a7d22 --- /dev/null +++ b/src/test/__snapshots__/cli.test.ts.snap @@ -0,0 +1,246 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Generate ZWO examples/comments.txt 1`] = ` +" + Workout with comments + + + bike + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" +`; + +exports[`Generate ZWO examples/darth-vader.txt 1`] = ` +" + Darth Vader + HumanPowerPerformance.com + Sign up for coaching with HumanPowerPerformance.com and get custom workouts and training plans + bike + + + + + + +" +`; + +exports[`Generate ZWO examples/halvfems.txt 1`] = ` +" + Halvfems + + Named after the number 90 in Danish, this workout is focused sweet spot training, centered around 90% of FTP. +This pairs with Devedeset (90 in Croatian) and Novanta (90 in Italian) to make up the sweet spot trifecta in this plan. +The workouts are alphabetically ordered from easiest to hardest, so enjoy the middle of these three challenging workouts today... + bike + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" +`; + +exports[`Generate ZWO examples/threshold-pushing.txt 1`] = ` +" + Threshold pushing + R.Saarsoo + Start with a good warm up (10 minutes Zone 1, then 5 minutes Zone 2, +5 minutes Zone 3 followed by 5 minutes easy spinning). +Then straight in at Threshold Pushing powers for 12 mins. +Have 10 mins easy soft pedalling and repeat - warm down 15 minutes. +This session is designed to increase your FTP from below. +Working predominately aerobic metabolism. +In time your body will become more comfortable at these powers +and your FTP will increase. + bike + + + + + + + + +" +`; + +exports[`Generate stats examples/comments.txt 1`] = ` +" +Total duration: 24 minutes + +Average intensity: 60% +Normalized intensity: 74% + +TSS #1: 17 +TSS #2: 22 + +Zone Distribution: + 15 min - Z1: Recovery + 5 min - Z2: Endurance + 2 min - Z3: Tempo + 1 min - Z4: Threshold + 3 min - Z5: VO2 Max + 0 min - Z6: Anaerobic +" +`; + +exports[`Generate stats examples/darth-vader.txt 1`] = ` +" +Total duration: 43 minutes + +Average intensity: 79% +Normalized intensity: 84% + +TSS #1: 48 +TSS #2: 51 + +Zone Distribution: + 10 min - Z1: Recovery + 0 min - Z2: Endurance + 30 min - Z3: Tempo + 0 min - Z4: Threshold + 0 min - Z5: VO2 Max + 3 min - Z6: Anaerobic +" +`; + +exports[`Generate stats examples/halvfems.txt 1`] = ` +" +Total duration: 62 minutes + +Average intensity: 74% +Normalized intensity: 81% + +TSS #1: 62 +TSS #2: 68 + +Zone Distribution: + 22 min - Z1: Recovery + 2 min - Z2: Endurance + 0 min - Z3: Tempo + 37 min - Z4: Threshold + 1 min - Z5: VO2 Max + 0 min - Z6: Anaerobic +" +`; + +exports[`Generate stats examples/threshold-pushing.txt 1`] = ` +" +Total duration: 79 minutes + +Average intensity: 69% +Normalized intensity: 78% + +TSS #1: 69 +TSS #2: 81 + +Zone Distribution: + 42 min - Z1: Recovery + 13 min - Z2: Endurance + 0 min - Z3: Tempo + 24 min - Z4: Threshold + 0 min - Z5: VO2 Max + 0 min - Z6: Anaerobic +" +`; diff --git a/src/test/cli.test.ts b/src/test/cli.test.ts new file mode 100644 index 0000000..187d07d --- /dev/null +++ b/src/test/cli.test.ts @@ -0,0 +1,30 @@ +import * as fs from "fs"; +import { generateZwo } from "../generateZwo"; +import { parse } from "../parser"; +import { stats } from "../stats"; + +const createStats = (filename: string) => stats(parse(fs.readFileSync(filename, "utf8"))); +const createZwo = (filename: string) => generateZwo(parse(fs.readFileSync(filename, "utf8"))); + +const filenames = [ + "examples/comments.txt", + "examples/darth-vader.txt", + "examples/halvfems.txt", + "examples/threshold-pushing.txt", +]; + +describe("Generate ZWO", () => { + filenames.forEach((filename) => { + it(filename, () => { + expect(createZwo(filename)).toMatchSnapshot(); + }); + }); +}); + +describe("Generate stats", () => { + filenames.forEach((filename) => { + it(filename, () => { + expect(createStats(filename)).toMatchSnapshot(); + }); + }); +});