Skip to content

Commit

Permalink
Add karma / mocha tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsergey committed Apr 18, 2020
1 parent 5e2dc8f commit 5fc8433
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ The node.js, browser-sync and Docker methods options will serve the website on p

Note that if you're using Docker on Windows or OS X via VirtualBox, you'll have to use the IP address of the Linux VM (usually 192.168.99.100) that is hosting Docker, instead of `localhost`. The Dockerfile.dev method will mount the app source as a volume so changes will be reflected when the browser is refreshed.

### Running test cases

Install [node.js](https://nodejs.org/) and run:
* `npm install`
* `npm test`

You can use Google Chrome to debug test cases using DevTools:
* `npm test:watch:chrome`

### Translations

Localization files can be found in `app/locale`. The `app/locale/en.json` file is purposefully missing because the English strings are used as the translation keys. Strings which require interpolation are defined in app.js so that they can be displayed immediately as a fallback until the actual locale json file finishes loading.
41 changes: 41 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = function( config ) {
config.set( {
browsers: [ 'jsdom' ],
frameworks: [ 'mocha' ],

plugins: [
'karma-chrome-launcher',
'karma-jsdom-launcher',
'karma-mocha',
'karma-mocha-reporter',
'karma-sourcemap-loader',
'karma-webpack',
],

files: [
// since it's not a module, we include it directly
'app/lib/string/String.js',
'app/js/actions.js',
'app/js/ffxivcraftmodel.js',
'test/**/*Test.js',
],

preprocessors: {
'app/**/*.js': [ 'sourcemap' ],
'test/**/*.js': [ 'webpack', 'sourcemap' ],
},

reporters: [
'mocha',
],

mochaReporter: {
output: 'autowatch',
},

webpack: {
mode: 'development',
},

});
};
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@
"serve-static": "^1.10.0"
},
"devDependencies": {
"browser-sync": "^2.23.6"
"assert": "^2.0.0",
"browser-sync": "^2.23.6",
"jsdom": "^16.2.2",
"karma": "^5.0.1",
"karma-chrome-launcher": "^3.1.0",
"karma-jsdom-launcher": "^8.0.2",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^4.0.2",
"mocha": "^7.1.1",
"webpack": "^4.42.1"
},
"scripts": {
"test": "karma start karma.conf.js --single-run",
"test:watch": "karma start karma.conf.js --no-single-run",
"test:watch:chrome": "karma start karma.conf.js --no-single-run --browsers Chrome"
}
}
28 changes: 28 additions & 0 deletions test/OddlySpecificChainmailSheetTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import assert from "assert";
import ArmorerRecipes from "../app/data/recipedb/Armorer";
import simFinalState from "./simFinalState";

const CRAFTER = new Crafter('Armorer', 80, 2535, 2163, 486, false, AllActions);

const RECIPE = {
startQuality: 0,
...ArmorerRecipes.find( ({id}) => id === 'af91eefbcf4' ),
};
RECIPE.suggestedCraftsmanship = RECIPE.suggestedCraftsmanship || SuggestedCraftsmanship[RECIPE.level];
RECIPE.suggestedControl = RECIPE.suggestedControl || SuggestedControl[RECIPE.level];

describe("Oddly Specific Chainmail Sheet", () => {
it("First Reflect: Quality increases by 482", () => {
var finalState = simFinalState( CRAFTER, RECIPE, [
AllActions.reflect
] );
assert.equal(482, finalState.qualityState);
});
it("Reflect, Groundwork increases progress by 1323", () => {
var finalState = simFinalState( CRAFTER, RECIPE, [
AllActions.reflect,
AllActions.groundwork
] );
assert.equal(1323, finalState.progressState);
});
});
33 changes: 33 additions & 0 deletions test/ffxivcraftmodelTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from "assert";
import simFinalState from "./simFinalState";

const INIT_CP = 180;

describe("FFXIV Crafting Model", () => {

it("Can craft Zelkova Fishing Rod with 3 basic synth", () => {
var crafter = new Crafter('Carpenter', 80, 2000, 0, INIT_CP, false, AllActions);
// Zelkova Fishing Rod
var recipe = new Recipe(70, 290, 2214, 80, 0, 11736, 1076, undefined);
var sequence = [ AllActions.basicSynth2, AllActions.basicSynth2, AllActions.basicSynth2 ];
var finalState = simFinalState( crafter, recipe, sequence );

assert.equal(finalState.cpState, INIT_CP);
assert.equal(finalState.lastStep, 3);
assert.equal(finalState.progressState, 2466);
assert.equal(finalState.step, 3);
});

it("Will not craft Zelkova Fishing Rod with only 2 basic synth", () => {
var crafter = new Crafter('Carpenter', 80, 2000, 0, INIT_CP, false, AllActions);
// Zelkova Fishing Rod
var recipe = new Recipe(70, 290, 2214, 80, 0, 11736, 1076, undefined);
var sequence = [ AllActions.basicSynth2, AllActions.basicSynth2 ];
var finalState = simFinalState( crafter, recipe, sequence );

assert.equal(finalState.cpState, INIT_CP);
assert.equal(finalState.lastStep, 2);
assert.equal(finalState.progressState, 1644);
assert.equal(finalState.step, 2);
});
});
16 changes: 16 additions & 0 deletions test/simFinalState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default function simFinalState( crafter, recipe, sequence ) {
var synth = new Synth(crafter, recipe, 0, 1.0, false, 0);
var startState = NewStateFromSynth(synth);

var synth = new Synth(crafter, recipe, 0, 1.0, true, 0);
var synthNoConditions = new Synth(crafter, recipe, 0, 1.0, false, 0);

var init = {
seed: Math.seed,
synth: synth,
startState: NewStateFromSynth(synth),
startStateNoConditions: NewStateFromSynth(synthNoConditions),
sequence: sequence
};
return simSynth(sequence, startState, false, true, true, undefined);
}

0 comments on commit 5fc8433

Please sign in to comment.