Added test suite and production builder

This commit is contained in:
WatDuhHekBro 2020-08-25 21:49:08 -05:00
parent 4a6754d21e
commit 8ca171e924
8 changed files with 1281 additions and 5 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ dist/
data/
tmp/
test*
!test/
*.bat
desktop.ini

16
docs/GettingStarted.md Normal file
View File

@ -0,0 +1,16 @@
# Getting Started
1. `npm install`
2. `npm run build`
3. `npm start`
# Getting Started (Developers)
1. `npm install`
2. `npm run dev`
3. Familiarize yourself with the [project's structure](Specifications.md).
4. Make sure to avoid using `npm run build`! This will remove all your dev dependencies (in order to reduce space used). Instead, use `npm run once` to compile and build in non-dev mode.
5. Begin developing.
## Don't forget to...
- ...update the [changelog](CHANGELOG.md) and any other necessary docs.
- ...update the version numbers in `package.json` and `package-lock.json`.
- ...make sure the test suite passes by running `npm test`.

View File

@ -9,6 +9,7 @@ The top-level directory is reserved for files that have to be there for it to wo
- `<file>.ts`: All commands at this level will have the `Miscellaneous` category.
- `events`: Here's the place to store events. The file name determines the event type.
- `dist`: This is where the runnable code in `src` compiles to. (The directory structure mirrors `src`.)
- `test`: Used for all the unit tests.
- `data`: Holds all the dynamic data used by the bot. This is what you modify if you want to change stuff for just your instance of the bot.
- `standard`: Contains all the standard data to be used with the project itself. It's part of the code and will not be checked for inaccuracies because it's not meant to be easily modified.
- `docs`: Used for information about the design of the project.

1183
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,17 +11,20 @@
},
"devDependencies": {
"@types/inquirer": "^6.5.0",
"@types/mocha": "^8.0.3",
"@types/node": "^14.0.22",
"@types/ws": "^7.2.6",
"mocha": "^8.1.2",
"ts-node": "^9.0.0",
"tsc-watch": "^4.2.9",
"typescript": "^3.9.6"
},
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"autobuild": "tsc && npm start",
"build": "tsc && npm prune --production",
"start": "node dist/index.js",
"dev": "tsc-watch --onSuccess \"node dist/index.js dev\""
"once": "tsc && npm start",
"dev": "tsc-watch --onSuccess \"node dist/index.js dev\"",
"test": "mocha --require ts-node/register --extension ts --recursive"
},
"keywords": [
"discord.js",

View File

@ -105,6 +105,8 @@ $.error = (...args: any[]) => {
logs.verbose += text;
};
// Be as verbose as possible. If anything might help when debugging an error, then include it. This only shows in your console if you run this with "dev", but you can still get it from "logs.verbose".
// $.debug(`core/lib::parseArgs("testing \"in progress\"") = ["testing", "in progress"]`) --> <path>/::(<object>.)<function>(<args>) = <value>
// Would probably be more suited for debugging program logic rather than function logic, which can be checked using unit tests.
$.debug = (...args: any[]) => {
if(process.argv[2] === "dev" && enabled)
console.debug(chalk.white.bgGray(formatTimestamp()), chalk.white.bgBlue("DEBUG"), ...args);

69
test/wrappers.ts Normal file
View File

@ -0,0 +1,69 @@
import {strict as assert} from "assert";
import {NumberWrapper, StringWrapper, ArrayWrapper} from "../src/core/wrappers";
// I can't figure out a way to run the test suite while running the bot.
describe("Wrappers", () => {
describe("NumberWrapper", () => {
describe("#pluralise()", () => {
it('should return "5 credits"', () => {
assert.equal(new NumberWrapper(5).pluralise("credit", "s"), "5 credits");
})
it('should return "1 credit"', () => {
assert.equal(new NumberWrapper(1).pluralise("credit", "s"), "1 credit");
})
it('should return "-1 credits"', () => {
assert.equal(new NumberWrapper(-1).pluralise("credit", "s"), "-1 credits");
})
it('should be able to work with a plural suffix', () => {
assert.equal(new NumberWrapper(2).pluralise("part", "ies", "y"), "2 parties");
})
it('should be able to work with a singular suffix', () => {
assert.equal(new NumberWrapper(1).pluralise("part", "ies", "y"), "1 party");
})
it('should be able to exclude the number', () => {
assert.equal(new NumberWrapper(1).pluralise("credit", "s", "", true), "credit");
})
})
describe("#pluraliseSigned()", () => {
it('should return "-1 credits"', () => {
assert.equal(new NumberWrapper(-1).pluraliseSigned("credit", "s"), "-1 credits");
})
it('should return "+0 credits"', () => {
assert.equal(new NumberWrapper(0).pluraliseSigned("credit", "s"), "+0 credits");
})
it('should return "+1 credit"', () => {
assert.equal(new NumberWrapper(1).pluraliseSigned("credit", "s"), "+1 credit");
})
})
})
describe("StringWrapper", () => {
describe("#replaceAll()", () => {
it('should convert "test" to "zesz"', () => {
assert.equal(new StringWrapper("test").replaceAll('t', 'z'), "zesz");
})
})
describe("#toTitleCase()", () => {
it('should capitalize the first letter of each word', () => {
assert.equal(new StringWrapper("yeetus deletus find salvation from jesus").toTitleCase(), "Yeetus Deletus Find Salvation From Jesus");
})
})
})
describe("ArrayWrapper", () => {
describe("#split()", () => {
it('should split [1,2,3,4,5,6,7,8,9,10] into [[1,2,3],[4,5,6],[7,8,9],[10]]', () => {
assert.deepEqual(new ArrayWrapper([1,2,3,4,5,6,7,8,9,10]).split(3), [[1,2,3],[4,5,6],[7,8,9],[10]]);
})
})
})
})

View File

@ -13,5 +13,6 @@
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"removeComments": true
}
},
"exclude": ["test"]
}