constructor({log = new Log(), cacheDir = path.join(os.tmpdir(), '.cache')} = {}) { // Get the nodecache opts super(); // Set some things this.log = log; this.cacheDir = cacheDir; // Ensure the cache dir exists mkdirp.sync(this.cacheDir); }
beforeAll(async function(state) { const DEVTOOLS_DIR = path.dirname( require.resolve('chrome-devtools-frontend/front_end/shell.json')); const frontendFolder = await fsMkdtemp(path.join(os.tmpdir(), 'ndb-test-frontend-')); await new ReleaseBuilder([ path.join(__dirname, '..', 'front_end'), DEVTOOLS_DIR, path.join(__dirname, '..'), path.join(__dirname, '..', '..', '..') ], frontendFolder).buildApp('integration_test_runner'); state.frontendFolder = frontendFolder; });
describe('#downloadFile', function downloadFileSuite() { const downloadPath = os.tmpdir(); this.timeout(timeout); before(function before() { utils.handleRatelimit(bot, 'downloadFile', this); }); it('should download a file', function test() { return bot.downloadFile(FILE_ID, downloadPath) .then(filePath => { assert.ok(is.string(filePath)); assert.equal(path.dirname(filePath), downloadPath); assert.ok(fs.existsSync(filePath)); fs.unlinkSync(filePath); // Delete file after test }); }); });
xit('repl and uncaught error', async function() { const configDir = await fsMkdtemp(path.join(os.tmpdir(), 'ndb-test-')); const frontend = await launch({ configDir: configDir, argv: ['.'], cwd: path.join(__dirname, 'assets', 'test-project'), debugFrontend: false, doNotCopyPreferences: true }); const consolePrompt = await frontend.waitForSelector('body /deep/ #console-prompt'); await frontend.type('body /deep/ #console-prompt', 'require("child_process").spawn("!@#$%")'); await consolePrompt.press('Enter'); await frontend.type('body /deep/ #console-prompt', 'console.log(42)'); consolePrompt.press('Enter'); const consoleMessage = await frontend.waitForSelector('body /deep/ .console-message-wrapper:nth-child(6) .console-message-text'); assert.equal('42', await frontend.evaluate(x => x.innerText, consoleMessage)); await frontend.close(); await util.promisify(removeFolder)(configDir); });
constructor(frontend) { process.title = 'ndb/ndd_service'; this._disconnectPromise = new Promise(resolve => process.once('disconnect', () => resolve(DebugState.PROCESS_DISCONNECT))); this._connected = new Set(); this._frontend = frontend; const pipePrefix = process.platform === 'win32' ? '\\\\.\\pipe\\' : os.tmpdir(); const pipeName = `node-ndb.${process.pid}.sock`; this._pipe = path.join(pipePrefix, pipeName); const server = net.createServer(socket => { socket.on('data', async d => { const runSession = await this._startSession(JSON.parse(d), frontend); socket.write('run'); runSession(); }); socket.on('error', e => caughtErrorDebug(e)); }).listen(this._pipe); server.unref(); }
test('pino.destination', async ({ same }) => { const tmp = join( os.tmpdir(), '_' + Math.random().toString(36).substr(2, 9) ) const instance = pino(pino.destination(tmp)) instance.info('hello') await watchFileCreated(tmp) const result = JSON.parse(readFileSync(tmp).toString()) delete result.time same(result, { pid, hostname, level: 30, msg: 'hello' }) })
describe('#Lando', () => { // @todo: do we need a stronger test? presumably downstream requires handle that? it('should return a Lando instance with correct default options', () => { const lando = new Lando(); lando.should.be.an.instanceof(Lando); }); it('should use prexisting instance id if possible', () => { filesystem({ '/tmp/cache/id': '"24601"', }); const lando = new Lando({userConfRoot: '/tmp'}); lando.config.id.should.equal('24601'); lando.config.user.should.equal('24601'); filesystem.restore(); }); it('should set and persitent cache an instance id if needed', () => { filesystem(); const lando = new Lando({userConfRoot: os.tmpdir()}); const idPath = path.join(lando.config.userConfRoot, 'cache', 'id'); fs.existsSync(idPath).should.be.true; lando.cache.get('id').should.equal(lando.config.id); filesystem.restore(); }); });
describe('#which', () => { const savePath = process.env.PATH; beforeEach(() => { process.env.PATH = os.tmpdir(); const bin = {}; const content = 'Gorillaz on buildings throwing explosive bananas at each other with mathematical precision'; bin[path.join(os.tmpdir(), 'GORILLA.BAS')] = content; filesystem(bin); }); it('should return the same as shelljs.which', () => { const shell = new Shell(); const which1 = shell.which('GORILLA.BAS'); const which2 = _shell.which('GORILLA.BAS'); _.toString(which1).should.equal(_.toString(which2)); }); it('should return null if command is not found', () => { const shell = new Shell(); const wolfenstein = shell.which('WOLFENSTEIN2D.exe'); expect(wolfenstein).to.be.null; }); afterEach(() => { filesystem.restore(); process.env.PATH = savePath; }); });
it('Stay attached', async function(state) { const configDir = await fsMkdtemp(path.join(os.tmpdir(), 'ndb-test-')); const frontend = await launch({ configDir: configDir, argv: ['.'], cwd: path.join(__dirname, 'assets', 'test-project'), debugFrontend: false, doNotCopyPreferences: true, appName: 'integration_test_runner', releaseFrontendFolder: state.frontendFolder, doNotProcessExit: true }); await setupHelpers(frontend); await frontend.setSetting('waitAtEnd', true); frontend.runConfiguration('atexit'); await frontend.waitForConsoleMessage('42'); const processes = await frontend.nodeProcess(); processes.sort(); assert.equal(`node -e process.once('exit', _ => console.log(42))`, processes[0]); assert.equal(`node npm run atexit`, processes[1]); const targetDestroyed = frontend.waitTargetDestroyed(2); await frontend.killProcess(`node -e process.once('exit', _ => console.log(42))`); await targetDestroyed; assert.deepStrictEqual([], await frontend.nodeProcess()); await frontend.close(); await util.promisify(removeFolder)(configDir); });
test('auto pino.destination with a string', async ({ same }) => { const tmp = join( os.tmpdir(), '_' + Math.random().toString(36).substr(2, 9) ) const instance = pino(tmp) instance.info('hello') await watchFileCreated(tmp) const result = JSON.parse(readFileSync(tmp).toString()) delete result.time same(result, { pid, hostname, level: 30, msg: 'hello' }) })
xit('terminal exit', async function() { const configDir = await fsMkdtemp(path.join(os.tmpdir(), 'ndb-test-')); const frontend = await launch({ configDir: configDir,
xit('run configuration', async function() { const configDir = await fsMkdtemp(path.join(os.tmpdir(), 'ndb-test-')); const frontend = await launch({ configDir: configDir, argv: ['.'], cwd: path.join(__dirname, 'assets', 'test-project'), debugFrontend: false, doNotCopyPreferences: true }); const configItem = await frontend.waitForSelector('body /deep/ .list-item'); configItem.hover(); const runButton = await frontend.waitForSelector('body /deep/ .list-item /deep/ [aria-label=Run]', { visible: true }); runButton.click(); const consoleMessage = await frontend.waitForSelector('body /deep/ .console-message-wrapper:nth-child(3) .console-message-text'); assert.equal('42', await frontend.evaluate(x => x.innerText, consoleMessage)); await frontend.close(); await util.promisify(removeFolder)(configDir); });
xit('run, pause at start, kill', async function() { const configDir = await fsMkdtemp(path.join(os.tmpdir(), 'ndb-test-')); const frontend = await launch({ configDir: configDir,
test('does not override opts with a string as second argument', async ({ same }) => { const tmp = join( os.tmpdir(), '_' + Math.random().toString(36).substr(2, 9) ) const instance = pino({ timestamp: () => ',"time":"none"' }, tmp) instance.info('hello') await watchFileCreated(tmp) const result = JSON.parse(readFileSync(tmp).toString()) same(result, { pid, hostname, level: 30, time: 'none', msg: 'hello' }) })
test('auto pino.destination with a string as second argument', async ({ same }) => { const tmp = join( os.tmpdir(), '_' + Math.random().toString(36).substr(2, 9) ) const instance = pino(null, tmp) instance.info('hello') await watchFileCreated(tmp) const result = JSON.parse(readFileSync(tmp).toString()) delete result.time same(result, { pid, hostname, level: 30, msg: 'hello' }) })