Get the TypeScript TextTests working more conveniently

This commit is contained in:
emily 2023-11-03 15:26:43 +01:00
parent 3fb6c60ad1
commit fa5ea72fd2
4 changed files with 49 additions and 21 deletions

View File

@ -10,23 +10,9 @@ Install dependencies
npm install
```
## Running app
_You may need to install `ts-node`_
## Run the unit tests from the Command-Line
```sh
npx ts-node test/golden-master-text-test.ts
```
Or with number of days as args:
```sh
npx ts-node test/golden-master-text-test.ts 10
```
## Running tests
To run all tests
### Jest way
There are two unit test frameworks to choose from, Jest and Mocha.
```sh
npm run test:jest
@ -38,8 +24,34 @@ To run all tests in watch mode
npm run test:jest:watch
```
### Mocha way
Mocha
```sh
npm run test:mocha
```
## Run the TextTest fixture from the Command-Line
_You may need to install `ts-node`_
```sh
npx ts-node test/golden-master-text-test.ts
```
Or with number of days as args:
```sh
npx ts-node test/golden-master-text-test.ts 10
```
You should make sure the command shown above works when you execute it in a terminal before trying to use TextTest (see below).
## Run the TextTest approval test that comes with this project
There are instructions in the [TextTest Readme](../texttests/README.md) for setting up TextTest. You will need to specify the Python executable and interpreter in [config.gr](../texttests/config.gr). Uncomment these lines:
executable:${TEXTTEST_HOME}/python/texttest_fixture.py
interpreter:python

View File

@ -1,5 +1,7 @@
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), //
@ -20,11 +22,11 @@ if (process.argv.length > 2) {
days = +process.argv[2];
}
for (let i = 0; i < days; i++) {
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(element.name + ', ' + element.sellIn + ', ' + element.quality);
});
console.log();

View File

@ -0,0 +1,14 @@
#!/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)

View File

@ -32,8 +32,8 @@ diff_program:meld
#interpreter:perl
# Settings for the TypeScript version
#executable:${TEXTTEST_HOME}/TypeScript/test/golden-master-text-test.js
#interpreter:node
#executable:${TEXTTEST_HOME}/TypeScript/texttest_rig.py
#interpreter:python
# Settings for the Julia version
#executable:${TEXTTEST_HOME}/julia/texttest_fixture.jl