mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-04 09:11:39 +00:00
refactor snapshot tests
- refactor snapshot tests to not use the console output and text test. - Remove texttest rig python script - generate snapshot file
This commit is contained in:
parent
843a2c639b
commit
40c997220d
@ -1,34 +0,0 @@
|
||||
import { Item, GildedRose } from '../app/gilded-rose';
|
||||
|
||||
console.log("OMGHAI!")
|
||||
|
||||
const items = [
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)];
|
||||
|
||||
|
||||
const gildedRose = new GildedRose(items);
|
||||
|
||||
let days: number = 2;
|
||||
if (process.argv.length > 2) {
|
||||
days = +process.argv[2];
|
||||
}
|
||||
|
||||
for (let i = 0; i < days + 1; i++) {
|
||||
console.log("-------- day " + i + " --------");
|
||||
console.log("name, sellIn, quality");
|
||||
items.forEach(element => {
|
||||
console.log(element.name + ', ' + element.sellIn + ', ' + element.quality);
|
||||
|
||||
});
|
||||
console.log();
|
||||
gildedRose.updateQuality();
|
||||
}
|
||||
1501
TypeScript/test/jest/__snapshots__/approvals.spec.ts.snap
Normal file
1501
TypeScript/test/jest/__snapshots__/approvals.spec.ts.snap
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,54 +1,27 @@
|
||||
import { Item, GildedRose } from '@/gilded-rose';
|
||||
import { Item, GildedRose } from "@/gilded-rose";
|
||||
|
||||
/**
|
||||
* This unit test uses [Jest Snapshot](https://goo.gl/fbAQLP).
|
||||
*
|
||||
* There are two test cases here with different styles:
|
||||
* <li>"foo" is more similar to the unit test from the 'Java' version
|
||||
* <li>"thirtyDays" is more similar to the TextTest from the 'Java' version
|
||||
*
|
||||
* I suggest choosing one style to develop and deleting the other.
|
||||
*/
|
||||
describe("Gilded Rose Approval", () => {
|
||||
it("should match the snapshot for thirty Days", () => {
|
||||
const items = [
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6),
|
||||
];
|
||||
|
||||
describe('Gilded Rose Approval', () => {
|
||||
const gildedRose = new GildedRose(items);
|
||||
|
||||
let gameConsoleOutput: string;
|
||||
let originalConsoleLog: (message: any) => void;
|
||||
let originalProcessArgv: string[]
|
||||
const days = 30;
|
||||
|
||||
function gameConsoleLog(msg: string) {
|
||||
if (msg) {
|
||||
gameConsoleOutput += msg;
|
||||
for (let i = 0; i < days; i++) {
|
||||
const updatedItems = gildedRose.updateQuality();
|
||||
expect(updatedItems).toMatchSnapshot();
|
||||
}
|
||||
gameConsoleOutput += "\n";
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
// prepare capturing console.log to our own gameConsoleLog.
|
||||
gameConsoleOutput = "";
|
||||
originalConsoleLog = console.log;
|
||||
console.log = gameConsoleLog;
|
||||
originalProcessArgv = process.argv;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// reset original console.log
|
||||
console.log = originalConsoleLog;
|
||||
process.argv = originalProcessArgv;
|
||||
});
|
||||
|
||||
it('should foo', () => {
|
||||
const gildedRose = new GildedRose([new Item('foo', 0, 0)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
|
||||
expect(items).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should thirtyDays', () => {
|
||||
process.argv = ["<node>", "<script", "30"];
|
||||
require('../golden-master-text-test.ts');
|
||||
|
||||
expect(gameConsoleOutput).toMatchSnapshot();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
This script uses npx to execute the TextTest Fixture for TypeScript.
|
||||
It is designed to be used by TextTest and specified in the file 'texttests/config.gr' in this repo.
|
||||
It is more convenient for TextTest to use since npx needs
|
||||
several arguments in addition to the one the TextTest fixture needs.
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
args = " ".join(sys.argv[1:])
|
||||
TEXTTEST_HOME = os.environ.get("TEXTTEST_HOME", os.getcwd())
|
||||
subprocess.run(f"npx ts-node {TEXTTEST_HOME}/TypeScript/test/golden-master-text-test.ts {args}", shell=True)
|
||||
Loading…
Reference in New Issue
Block a user