Skip to content

Commit

Permalink
Update setup.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
asamuzaK committed Dec 15, 2020
1 parent 4841681 commit 88107bd
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/setup.test.js
Expand Up @@ -983,6 +983,86 @@ describe('_createShellScript', () => {
await removeDir(dir, TMPDIR);
});

it('should create file', async () => {
let info;
const stubInfo = sinon.stub(console, 'info').callsFake(msg => {
info = msg;
});
const dir = path.join(TMPDIR, 'webextnativemsg');
const configPath = await createDirectory(path.join(dir, 'config'));
const shellPath = path.join(configPath, IS_WIN ? 'foo.cmd' : 'foo.sh');
const mainScriptFile = path.resolve('test/file/test.js');
const mainFilePath = mainScriptFile;
const setup = new Setup({
mainScriptFile,
hostName: 'foo'
});
const res = await setup._createShellScript(configPath);
const { calledOnce: infoCalled } = stubInfo;
stubInfo.restore();
const file = fs.readFileSync(shellPath, {
encoding: 'utf8',
flag: 'r'
});
assert.isTrue(infoCalled);
assert.strictEqual(info, `Created: ${shellPath}`);
assert.strictEqual(res, shellPath);
assert.isTrue(isFile(shellPath));
assert.isTrue(file.endsWith('\n'));
if (IS_WIN) {
assert.strictEqual(
file,
`@echo off\n${quoteArg(process.execPath)} ${quoteArg(mainFilePath)}\n`
);
} else {
assert.strictEqual(
file,
`#!${process.env.SHELL}\n${quoteArg(process.execPath)} ${quoteArg(mainFilePath)}\n`
);
}
await removeDir(dir, TMPDIR);
});

it('should create file', async () => {
let info;
const stubInfo = sinon.stub(console, 'info').callsFake(msg => {
info = msg;
});
const dir = path.join(TMPDIR, 'webextnativemsg');
const configPath = await createDirectory(path.join(dir, 'config'));
const shellPath = path.join(configPath, IS_WIN ? 'foo.cmd' : 'foo.sh');
const mainScriptFile = path.resolve('test/file/test.js');
const mainFilePath = mainScriptFile;
const setup = new Setup({
hostName: 'foo'
});
setup.mainScriptFile = mainScriptFile;
const res = await setup._createShellScript(configPath);
const { calledOnce: infoCalled } = stubInfo;
stubInfo.restore();
const file = fs.readFileSync(shellPath, {
encoding: 'utf8',
flag: 'r'
});
assert.isTrue(infoCalled);
assert.strictEqual(info, `Created: ${shellPath}`);
assert.strictEqual(res, shellPath);
assert.isTrue(isFile(shellPath));
assert.isTrue(file.endsWith('\n'));
if (IS_WIN) {
assert.strictEqual(
file,
`@echo off\n${quoteArg(process.execPath)} ${quoteArg(mainFilePath)}\n`
);
} else {
assert.strictEqual(
file,
`#!${process.env.SHELL}\n${quoteArg(process.execPath)} ${quoteArg(mainFilePath)}\n`
);
}
await removeDir(dir, TMPDIR);
});

it('should create file', async () => {
let info;
const stubInfo = sinon.stub(console, 'info').callsFake(msg => {
Expand Down

0 comments on commit 88107bd

Please sign in to comment.