Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('Test clasp push function', () => {
before(setup);
it('should push local project correctly', () => {
fs.writeFileSync('Code.js', TEST_CODE_JS);
fs.writeFileSync('.claspignore', '**/**\n!Code.js\n!appsscript.json');
const result = spawnSync(
CLASP, ['push'], { encoding: 'utf8', input: 'y' },
);
expect(result.stdout).to.contain('Pushed');
expect(result.stdout).to.contain('files.');
expect(result.stderr).to.equal('');
expect(result.status).to.equal(0);
});
// TODO: this test needs to be updated
it.skip('should return non-0 exit code when push failed', () => {
fs.writeFileSync('.claspignore', '**/**\n!Code.js\n!appsscript.json\n!unexpected_file');
fs.writeFileSync('unexpected_file', TEST_CODE_JS);
const result = spawnSync(
CLASP, ['push'], { encoding: 'utf8' },
);
expect(result.stderr).to.contain('Invalid value at');
expect(result.stderr).to.contain('UNEXPECTED_FILE');
expect(result.stderr).to.contain('Files to push were:');
expect(result.status).to.equal(1);
});
after(cleanup);
});
'UPDATE TxnTable t SET t.StringValue = @str WHERE t.Key = @key',
params: {
key: 'k1',
str: 'abcde',
},
},
(err, rowCount) => {
assert.ifError(err);
assert.strictEqual(rowCount, 1);
done();
}
);
});
// tslint:disable-next-line ban
it.skip('should execute a long running pdml statement', () => {
const count = 10000;
const tableData = new Array(count).fill(0).map((_, i) => {
return {Key: `longpdml${i}`, StringValue: 'a'};
});
const str = new Array(1000).fill('b').join('\n');
return database
.runTransactionAsync(transaction => {
transaction.insert('TxnTable', tableData);
return transaction.commit();
})
.then(() => {
return database.runPartitionedUpdate({
sql: `UPDATE TxnTable t SET t.StringValue = @str WHERE t.StringValue = 'a'`,
describe('Objects', () => {
// TODO: javascript new object is not supported for now
it.skip('new', () => expect('Doe\r\n').to.equals(new Run().test([
'function Person(first, last, age, eyecolor) { \
this.firstName = first; \
this.lastName = last; \
this.age = age; \
this.eyeColor = eyecolor; \
} \
var myFather = new Person("John", "Doe", 50, "blue"); \
var myMother = new Person("Sally", "Rally", 48, "green"); \
console.log(myFather.lastName) \
'])));
it.skip('new class', () => expect('const\r\nHi\r\n').to.equals(new Run().test([
'function Class1() { \
console.log("const"); \
} \
\
\
public run3(x, callback: (data: any) => void) { \
callback(x); \
} \
\
public run4(x) { \
console.log(x); \
} \
} \
\
const t = new Test(); \
t.run(); \
'])).to.equals('10\r\n20\r\n'));
// TODO: you can cast Camera => ICamera and convert method to function pointer
it.skip('Class - calling method via interface function', () => expect(new Run().test([
'interface ICamera { \
attachControl: (element: HTMLElement, noPreventDefault?: boolean) => void; \
checkInputs?: () => void; \
} \
\
class Camera implements ICamera { \
public checkInputs: () => void; \
\
public attachControl(element: HTMLElement, noPreventDefault?: boolean) { \
console.log(noPreventDefault); \
} \
} \
\
const c = new Camera(); \
\
const ci = c; \
describe('Objects', () => {
// TODO: javascript new object is not supported for now
it.skip('new', () => expect('Doe\r\n').to.equals(new Run().test([
'function Person(first, last, age, eyecolor) { \
this.firstName = first; \
this.lastName = last; \
this.age = age; \
this.eyeColor = eyecolor; \
} \
var myFather = new Person("John", "Doe", 50, "blue"); \
var myMother = new Person("Sally", "Rally", 48, "green"); \
console.log(myFather.lastName) \
'])));
it.skip('new class', () => expect('const\r\nHi\r\n').to.equals(new Run().test([
'function Class1() { \
console.log("const"); \
} \
\
Class1.prototype.sayHi = function () { \
console.log("Hi"); \
}; \
\
let c = new Class1(); \
c.sayHi(); \
'])));
it('object - spread assignment', () => expect('0\r\nfalse\r\n').to.equals(new Run().test([
'let options = { \
b1: false \
}; \
console.log(pickedCard.suit); \
'])));
it('this in function', () => expect('37\r\n').to.equals(new Run().test([
'var o = { \
prop: 37, \
f: function() { \
return this.prop; \
} \
}; \
\
console.log(o.f()); \
'])));
// TODO: this is not working in javascript
it.skip('this 2', () => expect('spades\r\n').to.equals(new Run().test([
'let deck = { \
suits: ["hearts", "spades", "clubs", "diamonds"], \
createCardPicker: function() { \
return function() { \
return {suit: this.suits[1]}; \
} \
} \
} \
\
let cardPicker = deck.createCardPicker(); \
let pickedCard = cardPicker(); \
\
console.log(pickedCard.suit); \
'])));
it('this - in an arrow function', () => expect('hearts\r\n').to.equals(new Run().test([
it('simple for (local)', () => expect('0\r\n1\r\n2\r\n3\r\n4\r\n').to.equals(new Run().test([
'let i; \
for (i = 0; i < 5; i++) { \
console.log(i); \
} \
'])));
it('simple for (global)', () => expect('0\r\n1\r\n2\r\n3\r\n4\r\n').to.equals(new Run().test([
'var i; \
for (i = 0; i < 5; i++) { \
console.log(i); \
} \
'])));
it.skip('simple for/in (local) ', () => expect('10\r\n20\r\n30\r\n').to.equals(new Run().test([
'let vals = [10, 20, 30]; \
let i; \
for (i in vals) { \
console.log(vals[i]); \
} \
'])));
it('simple for/in (local) ', () => expect('20\r\n30\r\n10\r\n3\r\n').to.equals(new Run().test([
'let vals = [10, 20, 30]; \
let i; \
for (i in vals) { \
console.log(vals[i]); \
} \
'])));
it('simple for/in (local) 1', () => expect(new Run().test([
'])));
it('var access variables within other functions', () => expect('11\r\n').to.equals(new Run().test([
'function f() { \
var a = 10; \
return function g() { \
var b = a + 1; \
return b; \
} \
} \
\
var g = f(); \
console.log(g()); \
'])));
it.skip('var access variables within other functions 2', () => expect('2\r\n').to.equals(new Run().test([
'function f() { \
var a = 1; \
\
a = 2; \
var b = g(); \
a = 3; \
\
return b; \
\
function g() { \
return a; \
} \
} \
\
console.write(f()); \
'])));
'])));
it('const declarations', () => expect('Cat\r\n').to.equals(new Run().test([
'const numLivesForCat = 9; \
const kitty = { \
name: "Aurora", \
numLives: numLivesForCat \
}; \
\
kitty.name = "Rory"; \
kitty.name = "Kitty"; \
kitty.name = "Cat"; \
console.log(kitty.name); \
'])));
it.skip('Array destructuring', () => expect('1\r\n2\r\n').to.equals(new Run().test([
'let input = [1, 2]; \
let [first, second] = input; \
console.log(first); \
console.log(second); \
'])));
});
console.log(x); \
x = 5 << 1; \
console.log(x); \
x = 5 >> 1; \
console.log(x); \
'])));
it('Logical', () => expect('true\r\nfalse\r\n').to.equals(new Run().test([
'let r, x = 6, y = 3; \
r = x < 10 && y > 1; \
console.log(r); \
r = x === 5 || y === 5; \
console.log(r); \
'])));
it.skip('Logical = not on boolean', () => expect('true\r\n').to.equals(new Run().test([
'let r; \
r = ~ false; \
console.log(r); \
'])));
it('Logical (basic 1)', () => expect(
'false\r\nfalse\r\ntrue\r\ntrue\r\ntrue\r\ntrue\r\nfalse\r\nfalse\r\nfalse\r\ntrue\r\nfalse\r\ntrue\r\n')
.to.equals(new Run().test([
'console.log(1 > 2); \
console.log(1 >= 2); \
console.log(1 < 2); \
console.log(1 <= 2); \
console.log(2 > 1); \
console.log(2 >= 1); \
console.log(2 < 1); \
console.log(2 <= 1); \