-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cfc660
commit c7f1f03
Showing
11 changed files
with
269 additions
and
9 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
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
Empty file.
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,3 @@ | ||
const chai = require("chai") | ||
const sinon = require("sinon"); | ||
|
Empty file.
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,34 @@ | ||
const { expect } = require('chai'); | ||
const { runFinally, asyncVerify } = require("run-verify"); | ||
const { Transform } = require('stream'); | ||
const checkDir = require('../../src/check-dir'); | ||
const shcmd = require("shcmd"); | ||
const { execSync, spawn } = require('child_process'); | ||
|
||
describe('checkDir', function () { | ||
const cwd = process.cwd(); | ||
afterEach(() => { | ||
process.chdir(cwd); | ||
}); | ||
|
||
it('checks if directory has existing files', function () { | ||
shcmd.mkdir("test/data/empty-dir"); | ||
process.chdir("test/data/empty-dir"); | ||
asyncVerify( | ||
() => checkDir(process.cwd()), | ||
(ret) => { | ||
expect(ret).to.equal(true) | ||
} | ||
); | ||
runFinally(() => { | ||
shcmd.rmdir("test/data/empty-dir") | ||
}) | ||
}); | ||
|
||
it('check non empty prompt', async function () { | ||
const output = execSync(`echo 'n' | node -e "require('./src/check-dir')('test/data')"`).toString(); | ||
expect(output).to.include("not empty"); | ||
|
||
}); | ||
|
||
}) |
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,25 @@ | ||
const expect = require("chai").expect; | ||
const shcmd = require("shcmd"); | ||
const { resolve } = require("path"); | ||
const { execSync } = require("child_process"); | ||
describe('create app', () => { | ||
beforeEach(() => { | ||
process.chdir(resolve(__dirname, "../../")); | ||
|
||
shcmd.mkdir("test/data/create-app-unit-test"); | ||
process.chdir("test/data/create-app-unit-test"); | ||
|
||
}); | ||
|
||
it('precondition: directory is created, and create app in cwd', () => { | ||
shcmd.exec("echo 'y' | node ../../../src/create-app"); | ||
|
||
}) | ||
afterEach(() => { | ||
process.chdir(resolve(__dirname, "../../")); | ||
|
||
execSync("rm -rf test/data/create-app-unit-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,26 @@ | ||
const expect = require("chai").expect; | ||
const shcmd = require("shcmd"); | ||
const { resolve } = require("path"); | ||
const { execSync } = require("child_process"); | ||
|
||
describe('index', function () { | ||
it('creates directory and then app in it', function () { | ||
process.chdir(resolve(__dirname, "../data")); | ||
shcmd.exec("echo 'y' | node ../../src/index new-app"); | ||
const output = shcmd.exec("ls new-app").stdout; | ||
|
||
expect(output).to.include("src"); | ||
expect(output).to.include("package.json"); | ||
expect(output).to.include("static"); | ||
expect(output).to.include("xclap"); | ||
execSync("rm -rf new-app"); | ||
process.chdir(".."); | ||
}).timeout(10000); | ||
|
||
it("aborts for non-empty directory", function () { | ||
process.chdir(resolve(__dirname, "../..")); | ||
shcmd.exec("echo 'n' | node ./src/index node_modules"); | ||
|
||
}) | ||
}) | ||
//require("../../src/"); |
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,76 @@ | ||
|
||
const { expect, should } = require("chai"); | ||
const { spawn, execSync } = require("child_process"); | ||
const Fs = require('fs') | ||
require("chai") | ||
describe('prepAppDir', function () { | ||
this.beforeEach(() => { | ||
process.chdir(require("path").resolve(__dirname, '../..')) | ||
}) | ||
const callSubroutineWithArgv2 = arg => { | ||
return spawn("node", ["-e", `process.argv[2]='${arg}'; require('./src/prep-app-dir')()`]); | ||
} | ||
it('requires process.argv2', async function () { | ||
const routine = callSubroutineWithArgv2(""); | ||
var output = "" | ||
routine.stdout.on("data", function (d) { | ||
output += d.toString(); | ||
}) | ||
|
||
routine.on("exit", () => { | ||
expect(output).to.include("pass '.' to use current directory") | ||
}); | ||
}); | ||
|
||
|
||
it('creates directory with name from process.argv2', async function () { | ||
expect(execSync("ls test/data").toString()).to.not.include("hello_app"); | ||
callSubroutineWithArgv2("./test/data/hello_app").on("exit", () => { | ||
expect(execSync("ls test/data").toString()).to.include("hello_app"); | ||
Fs.rmdirSync("test/data/hello_app"); | ||
}); | ||
}); | ||
|
||
it('when it throws a non-EEXIST exception, console logs msg Failed to create..', async function () { | ||
try { | ||
execSync("rm -rf test/data/no-writing && mkdir test/data/no-writing && chmod -w test/data/no-writing"); | ||
const routine = callSubroutineWithArgv2("./test/data/no-writing/new-app"); | ||
} catch (e) { | ||
expect(e.message).to.include("failed to") | ||
execSync("rm -rf test/data/no-writing"); | ||
} | ||
|
||
|
||
}); | ||
it('when process.argv2 ', function () { | ||
// expect(execSync("ls test/data").toString()).to.not.include("hello_app"); | ||
const nodeproc = callSubroutineWithArgv2("."); | ||
var output = "" | ||
nodeproc.stdout.on("data", function (d) { | ||
output += d.toString(); | ||
}) | ||
nodeproc.on("exit", () => { | ||
expect(output).to.include("Using current directory") | ||
}); | ||
}); | ||
it('when process.argv2 is existing directory', async function () { | ||
// expect(execSync("ls test/data").toString()).to.not.include("hello_app"); | ||
await new Promise(resolve => { | ||
const nodeproc = callSubroutineWithArgv2("./test/spec"); | ||
var output = "" | ||
nodeproc.stdout.on("data", function (d) { | ||
output += d.toString(); | ||
}) | ||
nodeproc.on("exit", (cod3) => { | ||
expect(cod3).to.equal(0); | ||
resolve(); | ||
}); | ||
}) | ||
}); | ||
|
||
|
||
|
||
|
||
|
||
}); | ||
|
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,46 @@ | ||
const sortDeps = require("../../src/sort-deps"); | ||
const { resolve } = require("path"); | ||
const _ = require("lodash"); | ||
const { execSync } = require("child_process"); | ||
const { expect } = require("chai"); | ||
const { unlink } = require("fs"); | ||
const { doesNotReject } = require("assert"); | ||
|
||
const xrequire = eval("require"); | ||
|
||
describe('sort-deps', function () { | ||
this.beforeEach(() => { | ||
process.chdir(resolve(__dirname, "../..")); | ||
}) | ||
it('sorts packages by keys', async function () { | ||
|
||
await new Promise(resolve => { | ||
const pkg = xrequire(resolve(__dirname, "../../template/_package"))({}, _.merge); | ||
sortDeps(pkg); | ||
const sortedDeps = pkg.dependencies; | ||
const sortedStr = Object.keys(sortedDeps).join("\n"); | ||
const qaSortedStr = execSync(`echo '${sortedStr}' > temp.txt && cat temp.txt |sort`).toString(); | ||
expect(sortedStr.trim()).to.equal(qaSortedStr.trim()); | ||
unlink('temp.txt', () => { | ||
resolve(); | ||
}); | ||
}) | ||
}); | ||
|
||
it("skip undefined sections", async () => { | ||
await new Promise(resolve => { | ||
|
||
const pkg = { | ||
dependencies: { "a": 1, "b": 1 } | ||
}; | ||
sortDeps(pkg); | ||
const sortedDeps = pkg.dependencies; | ||
const sortedStr = Object.keys(sortedDeps).join("\n"); | ||
const qaSortedStr = execSync(`echo '${sortedStr}' > temp.txt && cat temp.txt |sort`).toString(); | ||
expect(sortedStr.trim()).to.equal(qaSortedStr.trim()); | ||
unlink('temp.txt', () => { | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}) |
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,2 @@ | ||
import { loadTasks } from "@xarc/module-dev"; | ||
loadTasks(); |