Skip to content

Instantly share code, notes, and snippets.

View deepal's full-sized avatar

Deepal Jayasekara deepal

  • CompareTheMarket.com
  • London, United Kingdom
View GitHub Profile
const dns = require('dns');
const http = require('http');
const https = require('https');
const tls = require('tls');
const net = require('net');
const request = require('request');
const httpAgent = new http.Agent();
const httpsAgent = new https.Agent();
version: '3.4'
services:
test:
image: imega/busted
environment:
- LUA_PATH=/app/?.lua
command: busted /app
volumes:
- ./lib:/app/lib
describe("app module", function ()
describe("run() function", function ()
local check_env_stub = stub()
setup(function ()
package.preload["lib.check_env"] = function ()
return check_env_stub
end
end)
describe("check_env module", function ()
local check_env = require "lib.check_env"
before_each(function()
stub(os, "getenv")
end)
after_each(function ()
os.getenv:revert()
end)
local check_env = require "lib.check_env"
local sum = require "lib.sum"
local app = {}
app.run = function ()
if check_env() == true then
return string.format("Result of 10 + 20 is %s", sum(10, 20))
else
return nil
return function ()
if os.getenv("RUN_SUM") == "1" then
return true
else
return false
end
end
describe("sum module", function ()
it("should return the sum of two numbers", function ()
local sum = require "lib.sum"
local result = sum(100, 200)
assert.are.same(300, result)
end)
end)
return function (a, b)
return a + b
end
setFakeTime();
const startTimeToD = Date.now(); // set startTime with time-of-day clock
const startTimeMon = performance.now(); // set startTime with monotonic clock
setImmediate(() => {
correctTimeNTP(); // synchronise the clock
});
await doSomething();
@deepal
deepal / time.js
Last active March 15, 2022 20:43
const { execSync } = require("child_process");
const { setTimeout } = require("timers/promises");
const { performance } = require("perf_hooks")
function setFakeTime() {
const toTwoDigits = (num) => num.toString().padStart(2, "0");
const now = new Date();
const month = toTwoDigits(now.getMonth() + 1);
const date = toTwoDigits(now.getDate());
const hours = toTwoDigits(now.getHours());