Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Expect to call twice
t.true(['default', 'primary'].indexOf(name) !== -1);
return name;
},
}),
]);
return processor
.process(readFileSync(button, 'utf-8'), { from: button })
.then(({ css, messages }) => {
t.is(css.indexOf(UNUSED_EXPORT), -1);
t.is(messages.length, 0);
});
});
test.serial('namespace import', t => {
t.plan(3);
const button = join(namespaceImport, 'styles/button.css');
const processor = postcss([
modulesEs({
jsFiles: join(namespaceImport, 'App.js'),
getJsExports(name, jsFile) {
parseWithDefaultOptions(jsFile);
t.pass();
},
}),
]);
return processor
.process(readFileSync(button, 'utf-8'), { from: button })
t.is(member.person.toString(), res.body.person)
t.is(member.organisation.toString(), res.body.organisation)
t.is(member.validation.toString(), res.body.validation)
})
test.serial('Should return 404 code when queried non existing member', async t => {
const res = await request(server)
.get(`/api/members/asodifklamd`)
.set('Accept', 'application/json')
// This test is not ready since the return status was 500 not 404
const expectedResponseStatus = 500
t.is(res.status, expectedResponseStatus)
})
test.serial(
'Should not add an invalid member where referenced person or opp is not in DB',
async t => {
const newMember = new Member({
person: '5cc8d60b8b16812b5babcdef',
organisation: '5cc8d60b8b16812b5babcdef'
})
await request(server)
.post('/api/members')
.send(newMember)
.set('Accept', 'application/json')
const savedMember = await Member.findOne({
person: newMember.person,
organisation: newMember.organisation
}).exec()
.expect(200);
t.deepEqual(res.body.message, 'Login successful');
});
test('[Fail] Incorrect user password', async t => {
const res = await g.request
.post('/admin/login_action')
.send({
email: g.users[0].userEmail,
password: 'test1'
})
.expect(400);
t.deepEqual(res.body.message, 'Access denied. Check password and try again.');
});
test('[Fail] Delete own user account', async t => {
const res = await g.request
.post('/admin/user/delete')
.send({
userId: g.users[0]._id
})
.expect(400);
t.deepEqual(res.body.message, 'Unable to delete own user account');
});
test('[Fail] Delete invalid user ID', async t => {
const res = await g.request
.post('/admin/user/delete')
.send({
userId: 'invalid_user_id'
})
.expect(400);
});
ava.serial('.off() removes the event from #_events when no other observers exist', (t) => {
EventBus.on(eventNameMock, callbackMock);
EventBus.off(eventNameMock, callbackMock);
t.true(typeof EventBus._events.click === 'undefined');
});
ava.serial('.trigger() does not throw when an event does not exist', (t) => {
t.notThrows(() => EventBus.trigger(eventNameMock, 11, 3));
});
ava.serial('.trigger() calls each observer with #args', (t) => {
let val = 0;
const triggerFnMock = (plus, minus = 0) => {
val += plus;
val -= minus;
};
EventBus.on(eventNameMock, triggerFnMock);
EventBus.trigger(eventNameMock, 11, 3);
t.true(val === 8);
});
test.serial(
'Page.exposeFunction should be callable from-inside evaluateOnNewDocument',
async t => {
const { page, server } = t.context
let called = false
await page.exposeFunction('woof', function () {
called = true
})
await page.evaluateOnNewDocument(() => woof())
await page.reload()
t.true(called)
}
)
test.serial('Page.exposeFunction should survive navigation', async t => {
const { page, server } = t.context
await page.exposeFunction('compute', function (a, b) {
return a * b
})
await page.goto(server.EMPTY_PAGE)
const result = await page.evaluate(async function () {
return await compute(9, 4)
})
t.is(result, 36)
})
test.serial('Page.exposeFunction should await returned promise', async t => {
const { page, server } = t.context
await page.exposeFunction('compute', function (a, b) {
return Promise.resolve(a * b)
class B extends A {
constructor () {
super()
this.b = '2'
}
}
return new B()
})
const properties = await aHandle.getProperties()
t.is(await properties.get('a').jsonValue(), '1')
t.is(await properties.get('b').jsonValue(), '2')
}
)
test.serial('JSHandle.asElement should work', async t => {
const { page, server } = t.context
const aHandle = await page.evaluateHandle(() => document.body)
const element = aHandle.asElement()
t.truthy(element)
})
test.serial(
'JSHandle.asElement should return null for non-elements',
async t => {
const { page, server } = t.context
const aHandle = await page.evaluateHandle(() => 2)
const element = aHandle.asElement()
t.falsy(element)
}
)
test.serial('helper app paths', darwinTest(helperAppPathsTest))
test.serial('helper app paths test with app name needing sanitization', darwinTest(helperAppPathsTest, { name: '@username/package-name' }, '@username-package-name'))
const iconBase = path.join(__dirname, 'fixtures', 'monochrome')
const icnsPath = `${iconBase}.icns`
test.serial('macOS icon: .icns specified', darwinTest(iconTest, icnsPath, icnsPath))
test.serial('macOS icon: .ico specified (should replace with .icns)', darwinTest(iconTest, `${iconBase}.ico`, icnsPath))
test.serial('macOS icon: basename only (should add .icns)', darwinTest(iconTest, iconBase, icnsPath))
const extraInfoPath = path.join(__dirname, 'fixtures', 'extrainfo.plist')
const extraInfoParams = plist.parse(fs.readFileSync(extraInfoPath).toString())
test.serial('extendInfo: filename', darwinTest(extendInfoTest, extraInfoPath))
test.serial('extendInfo: params', darwinTest(extendInfoTest, extraInfoParams))
test.serial('darwinDarkModeSupport: should enable dark mode in macOS Mojave', darwinTest(async (t, opts) => {
opts.darwinDarkModeSupport = true
const obj = await packageAndParseInfoPlist(t, opts)
t.false(obj.NSRequiresAquaSystemAppearance, 'NSRequiresAquaSystemAppearance should be set to false')
}))
test.serial('protocol/protocol-name', darwinTest(async (t, opts) => {
opts.protocols = [
{
name: 'Foo',
schemes: ['foo']
},
{
name: 'Bar',
schemes: ['bar', 'baz']
}
t.context.connectorFunction = () => { };
sinon.stub(t.context, 'connectorFunction').returns({});
sinon.stub(t.context.resourceLoader, 'loadConnector').returns(t.context.connectorFunction);
new Sonarwhal({
connector: {
name: 'myconnector',
options: {}
}
});
t.true(t.context.connectorFunction.called);
});
test.serial('formatter should return the formatter configured', (t) => {
const sonarwhalObject = new Sonarwhal({
connector: 'connector',
formatters: ['formatter']
});
t.is(sonarwhalObject.formatters[0], 'formatter');
});
test.serial('pageContent should return the HTML', async (t) => {
const html = '';
t.context.connectorFunction = () => { };
sinon.stub(t.context, 'connectorFunction').returns({ html });
sinon.stub(t.context.resourceLoader, 'loadConnector').returns(t.context.connectorFunction);
const sonarwhalObject = new Sonarwhal({
};
let str = new Array(5000).join('|');
context.cookie('username', str);
t.is(overLength,true);
});
test.serial('controller / service', async t => {
context.service();
});
test.serial('config.onUnhandledRejection/onUncaughtException', async t => {
t.is('onUnhandledRejection',config.onUnhandledRejection('onUnhandledRejection'));
t.is('onUncaughtException',config.onUncaughtException('onUncaughtException'));
});
test.serial('download', async t => {
context.download(__dirname + '/controller.js');
t.is(context.body instanceof fs.ReadStream,true)
});
test.serial('download with content-type and disposition', async t => {
context.response.get = (key)=>{
if(key === 'Content-Type'){
return 'application/json'
}else if(key === 'Content-Disposition'){
return 'attachment:xxx'
}
}
context.download(__dirname + '/controller.js');
t.is(context.body instanceof fs.ReadStream,true)
});
return this;
}
FakeError.captureStackTrace = () => {};
global.Error = FakeError;
const result = stats.getDefaultProfileName(fn);
t.is(result, fn.name);
global.Error = currentError;
});
test.serial('if getDefaultProfileName will return the function name by itself when no stack can be found', (t) => {
const fn = function foo() {};
const currentError = global.Error;
function FakeError() {
this.stack = null;
return this;
}
FakeError.captureStackTrace = () => {};
global.Error = FakeError;
const result = stats.getDefaultProfileName(fn);