Skip to content

Commit

Permalink
test: setup vscode launch config + mocha integration
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatWizard committed Apr 22, 2024
1 parent 606fd81 commit 496a262
Show file tree
Hide file tree
Showing 57 changed files with 510 additions and 63 deletions.
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"program": "${workspaceFolder}/src/index.js",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"type": "node"
},
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": ["${workspaceFolder}/test/unit/**/*.test.js"],
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**"]
}
]
}
43 changes: 26 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "https://reliure.greatwizard.fr",
"author": {
"name": "Guillaume Gérard",
"url": "https://guillaume.sh"
"url": "https://guillaume.gerard.pm"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -35,27 +35,31 @@
"kindlegen",
"pandoc"
],
"main": "index.js",
"main": "src/index.js",
"bin": {
"reliure": "index.js"
"reliure": "src/index.js"
},
"scripts": {
"lint": "eslint . --cache",
"lint:fix": "eslint . --fix",
"pretest": "node scripts/github-releases.js",
"test": "npm-run-all test:*",
"test:custom-fonts-ttf": "./index.js --debug --epub --mobi --pdf tests/custom-fonts-ttf && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/custom-fonts-ttf/*.epub",
"test:custom-fonts-otf": "./index.js --debug --epub --mobi --pdf tests/custom-fonts-otf && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/custom-fonts-otf/*.epub",
"test:docx-one-file": "./index.js --debug --epub --mobi --pdf tests/docx-one-file && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/docx-one-file/*.epub",
"test:latex-one-file": "./index.js --debug --epub --mobi --pdf tests/latex-one-file && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/latex-one-file/*.epub",
"test:markdown-one-file": "./index.js --debug --epub --mobi --pdf tests/markdown-one-file && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/latex-one-file/*.epub",
"test:odt-one-file": "./index.js --debug --epub --mobi --pdf tests/odt-one-file && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/odt-one-file/*.epub ; echo 'This is fine.'",
"test:latex-multi-files": "./index.js --debug --epub --mobi --pdf tests/latex-multi-files && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/latex-multi-files/*.epub",
"test:markdown-multi-files": "./index.js --debug --epub --mobi --pdf tests/markdown-multi-files && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/markdown-multi-files/*.epub",
"test:metadata": "./index.js --debug --epub tests/metadata && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/metadata/*.epub",
"test:minimal": "./index.js --debug --epub tests/minimal && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/minimal/*.epub",
"test:toc": "./index.js --debug --epub --pdf tests/toc && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar tests/toc/*.epub",
"build": "pkg . --out-path=build"
"test": "npm-run-all test:unit test:acceptance",
"test:acceptance": "npm-run-all test:acceptance:*",
"test:acceptance:custom-fonts-ttf": "node ./src/index.js --debug --epub --pdf test/acceptance/custom-fonts-ttf && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/custom-fonts-ttf/*.epub",
"test:acceptance:custom-fonts-otf": "node ./src/index.js --debug --epub --pdf test/acceptance/custom-fonts-otf && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/custom-fonts-otf/*.epub",
"test:acceptance:docx-one-file": "node ./src/index.js --debug --epub --pdf test/acceptance/docx-one-file && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/docx-one-file/*.epub",
"test:acceptance:latex-one-file": "node ./src/index.js --debug --epub --pdf test/acceptance/latex-one-file && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/latex-one-file/*.epub",
"test:acceptance:markdown-one-file": "node ./src/index.js --debug --epub --pdf test/acceptance/markdown-one-file && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/latex-one-file/*.epub",
"test:acceptance:odt-one-file": "node ./src/index.js --debug --epub --pdf test/acceptance/odt-one-file && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/odt-one-file/*.epub ; echo 'This is fine.'",
"test:acceptance:latex-multi-files": "node ./src/index.js --debug --epub --pdf test/acceptance/latex-multi-files && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/latex-multi-files/*.epub",
"test:acceptance:markdown-multi-files": "node ./src/index.js --debug --epub --pdf test/acceptance/markdown-multi-files && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/markdown-multi-files/*.epub",
"test:acceptance:metadata": "node ./src/index.js --debug --epub test/acceptance/metadata && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/metadata/*.epub",
"test:acceptance:minimal": "node ./src/index.js --debug --epub test/acceptance/minimal && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/minimal/*.epub",
"test:acceptance:toc": "node ./src/index.js --debug --epub --pdf test/acceptance/toc && java -jar github_releases/w3c/epubcheck/epubcheck-*/epubcheck.jar test/acceptance/toc/*.epub",
"test:acceptance:mobi": "node ./src/index.js --debug --mobi test/acceptance/latex-multi-files",
"test:unit": "mocha test/unit/**/*.test.js",
"build": "pkg . --out-path=build",
"start": "node ./src/index.js"
},
"dependencies": {
"archiver": "^5.3.0",
Expand All @@ -77,14 +81,19 @@
"unzipper": "^0.10.10"
},
"devDependencies": {
"chai": "^4.4.1",
"download-github-release": "^0.3.2",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"mocha": "^10.4.0",
"mocha-sinon": "^2.1.2",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1"
"prettier": "^2.5.1",
"sinon": "^17.0.1",
"sinon-chai": "^3.7.0"
},
"githubReleases": {
"w3c/epubcheck": "v5.1.0"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
const clear = require('clear')
const path = require('path')

const build = require('./lib/build')
const getFormats = require('./lib/get-formats')
const { detectOrInstallKindlegen } = require('./lib/kindlegen')
const mergeConfig = require('./lib/merge-config')
const { printTitle, warn, info, success, error } = require('./lib/message')
const { getOptions, printVersion, printHelp } = require('./lib/options')
const { findConfig, readConfig, validateConfig } = require('./lib/read-config')
const build = require('./build')
const getFormats = require('./get-formats')
const { detectOrInstallKindlegen } = require('./kindlegen')
const mergeConfig = require('./merge-config')
const { printTitle, warn, info, success, error, log } = require('./message')
const { getOptions, printVersion, printHelp } = require('./options')
const { findConfig, readConfig, validateConfig } = require('./read-config')

const settings = { kindlegenPath: undefined }

Expand Down Expand Up @@ -70,7 +70,7 @@ const options = getOptions()
}

await Promise.all(builds)
console.log('✨ Done.')
log('✨ Done.')
})
.call(this, options)
.catch((e) => {
Expand Down
10 changes: 5 additions & 5 deletions lib/kindlegen.js → src/kindlegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { spawn } = require('child_process')
const tar = require('tar')
const unzipper = require('unzipper')

const { warn } = require('./message')
const { log, warn } = require('./message')
const { humanizePlatformArch } = require('./utils')

const kindlegenFilename = () => (process.platform === 'win32' ? 'kindlegen.exe' : 'kindlegen')
Expand Down Expand Up @@ -136,7 +136,7 @@ module.exports.detectOrInstallKindlegen = async (options = {}) => {
)}.`,
)
}
console.log(`KindleGen is a tool to convert files to the Kindle format (Mobi) enabling publishers to create great-looking books that work on all Kindle devices and apps.
log(`KindleGen is a tool to convert files to the Kindle format (Mobi) enabling publishers to create great-looking books that work on all Kindle devices and apps.
KindleGen is officially supported by Amazon.
To install KindleGen, you must accept the following terms of use: https://www.amazon.com/gp/feature.html?docId=1000599251`)
let install = options.mobi
Expand All @@ -151,15 +151,15 @@ To install KindleGen, you must accept the following terms of use: https://www.am
install = startInstall
}
if (install) {
console.log('* Download KindleGen')
log('* Download KindleGen')
let file = await downloadKindleGen(binUrl)
console.log('* Extract KindleGen in the current directory')
log('* Extract KindleGen in the current directory')
await extractKindleGen(file)
if (process.platform === 'darwin' || process.platform === 'linux') {
fs.chmodSync(kindlegenPath, 0o755)
}
}
console.log()
log()
return install ? kindlegenPath : undefined
}
}
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions lib/message.js → src/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ module.exports.warn = (message, icon = '📙') => {
module.exports.error = (message, icon = '📕') => {
console.error(chalk.red(`${icon} ${message}`))
}

module.exports.log = (message) => {
console.log(message)
}
File renamed without changes.
5 changes: 3 additions & 2 deletions lib/options.js → src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const chalk = require('chalk')
const commandLineArgs = require('command-line-args')
const commandLineUsage = require('command-line-usage')

const { log } = require('./message')
const { version } = require('../package.json')

const optionList = [
Expand Down Expand Up @@ -61,11 +62,11 @@ module.exports.getOptions = () => {
}

module.exports.printVersion = () => {
console.log(`v${version}`)
log(`v${version}`)
}

module.exports.printHelp = () => {
console.log(
log(
commandLineUsage([
{
header: 'How to use Reliure ⛑️',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/.gitignore → test/acceptance/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
*.synctex.gz
*.fdb_latexmk
*.fls
kindlegen*
kindlegen*
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions test/unit/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"mocha": true
},
"rules": {
"node/no-unpublished-require": [
"error",
{
"allowModules": ["chai", "mocha-sinon", "sinon-chai"]
}
]
}
}
6 changes: 6 additions & 0 deletions test/unit/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const chai = require('chai')

module.exports.setupSinon = () => {
chai.use(require('sinon-chai'))
require('mocha-sinon')
}
26 changes: 26 additions & 0 deletions test/unit/options.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const chai = require('chai')
const { setupSinon } = require('./helpers')

const { expect } = chai

setupSinon()

const message = require('../../src/message.js')

describe('options', function () {
let logSpy, subject

this.beforeEach(function () {
logSpy = this.sinon.spy(message, 'log')

subject = require('../../src/options.js')
})

it('prints version', function () {
subject.printVersion()

expect(logSpy.args[0]).to.match(
/v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,
)
})
})
Loading

0 comments on commit 496a262

Please sign in to comment.