Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: jest functional tests and xo linting (#1)
* test: added xo linting * test: added jest functional tests * test: added travis and appveyor config files * fix: fixed package name when using a full path as the target dir name
- Loading branch information
1 parent
6b4a1a9
commit 3617656
Showing
8 changed files
with
247 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
language: node_js | ||
sudo: false | ||
|
||
# Keep this in sync with appveyor.yml | ||
node_js: | ||
- '6' | ||
- '7' | ||
|
||
before_script: | ||
# If this command fails and you can't fix it, file an issue and add an exception to .nsprc | ||
- npm run nsp-check | ||
|
||
# Keep this in sync with appveyor.yml | ||
script: | ||
- npm run lint | ||
- npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const {spawn} = require("child_process"); | ||
|
||
module.exports = function cmdRunner(cmdArgs) { | ||
const spawnedProcess = spawn( | ||
process.execPath, cmdArgs, | ||
); | ||
|
||
return new Promise((resolve) => { | ||
let errorData = ""; | ||
let outputData = ""; | ||
|
||
spawnedProcess.stderr.on("data", (data) => { | ||
errorData += data; | ||
}); | ||
spawnedProcess.stdout.on("data", (data) => { | ||
outputData += data; | ||
}); | ||
|
||
spawnedProcess.on("close", (exitCode) => { | ||
resolve({ | ||
exitCode, | ||
stderr: errorData, | ||
stdout: outputData, | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const tmp = require("tmp"); | ||
const promisify = require("es6-promisify"); | ||
|
||
const createTempDir = promisify(tmp.dir, {multiArgs: true}); | ||
|
||
module.exports = function withTmpDir(testPromise) { | ||
return createTempDir({ | ||
prefix: "tmp-create-web-ext-", | ||
// This allows us to remove a non-empty tmp dir. | ||
unsafeCleanup: true, | ||
}) | ||
.then(([tmpPath]) => { | ||
return testPromise(tmpPath); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
const fs = require("mz/fs"); | ||
const linter = require("addons-linter"); | ||
const withTmpDir = require("./helpers/tmp-dir"); | ||
const cmdRunner = require("./helpers/cmd-runner"); | ||
|
||
const execDirPath = path.join(__dirname, "..", "bin"); | ||
|
||
describe("main", () => { | ||
test("creates files including manifest with correct name", () => withTmpDir( | ||
async (tmpPath) => { | ||
const projName = "target"; | ||
const targetDir = path.join(tmpPath, projName); | ||
|
||
const cmd = await cmdRunner([`${execDirPath}/create-webextension`, `${targetDir}`]); | ||
|
||
if (cmd.exitCode !== 0) { | ||
throw new Error(`Command Run Failed: ${cmd.stderr}`); | ||
} | ||
|
||
const contentStat = await fs.stat(path.join(targetDir, "content.js")); | ||
expect(contentStat.isDirectory()).toBeFalsy(); | ||
|
||
const bgStat = await fs.stat(path.join(targetDir, "background.js")); | ||
expect(bgStat.isDirectory()).toBeFalsy(); | ||
|
||
const manifest = await fs.readFile(path.join(targetDir, "manifest.json"), "utf-8"); | ||
const parsed = JSON.parse(manifest); | ||
expect(parsed.name).toEqual(projName); | ||
}) | ||
); | ||
|
||
test("created project is linted correctly", () => withTmpDir( | ||
async (tmpPath) => { | ||
const projName = "target"; | ||
const targetDir = path.join(tmpPath, projName); | ||
|
||
const cmd = await cmdRunner([`${execDirPath}/create-webextension`, `${targetDir}`]); | ||
|
||
if (cmd.exitCode !== 0) { | ||
throw new Error(`Command Run Failed: ${cmd.stderr}`); | ||
} | ||
|
||
const config = { | ||
_: [targetDir], | ||
logLevel: "fatal", | ||
stack: true, | ||
pretty: true, | ||
warningsAsErrors: false, | ||
metadata: false, | ||
output: "none", | ||
boring: false, | ||
selfHosted: false, | ||
}; | ||
const linterInstance = linter.createInstance({ | ||
config, | ||
runAsBinary: false, | ||
}); | ||
const summary = { | ||
errors: 0, | ||
notices: 0, | ||
warnings: 0, | ||
}; | ||
|
||
const instance = await linterInstance.run(); | ||
expect(instance.summary).toEqual(summary); | ||
}) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
install: | ||
- ps: Install-Product node $env:nodejs_version | ||
- set CI=true | ||
- set PATH=%APPDATA%\npm;%PATH% | ||
- npm install | ||
|
||
matrix: | ||
fast_finish: true | ||
|
||
build: off | ||
shallow_clone: true | ||
|
||
# Keep the following configs in sync with .travis.yml | ||
environment: | ||
matrix: | ||
- nodejs_version: '6' | ||
- nodejs_version: '7' | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- npm run lint | ||
- npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters