示例#1
0
 fs.writeFile(__dirname + '/a.log', 'aa', function (e) {
   should.ok(!e);
   Build.syntax(__dirname + '/a.log').should.eql([]);
   done();
 });
示例#2
0
 it('test find one none exist', function () {
   record = Table.findBy('email', 'nonexist').execSync();
   should.ok(!record);
 });
示例#3
0
 gruntSpawn('fail', function (stdout, code) {
   code.should.not.eql(0, 'should return error code on assertion failure');
   var outHasFail = /Fatal error: broken/.test(stdout);
   should.ok(outHasFail, 'stdout should contain output indicating failure.');
   done();
 });
示例#4
0
 urllib.request('http:/' + '/localhost:8124/aa', function (error, data, res) {
   should.ok(!error);
   data.toString().should.eql('hello world');
   res.should.have.property('statusCode', 200);
   done();
 });
示例#5
0
 tair.get('unittestjs2', 0, function (err, data) {
   should.not.exist(err);
   should.exist(data);
   should.ok(Buffer.isBuffer(data));
   done();
 }, false, 'buffer');
示例#6
0
 urllib.request(host + '/?a=12&code=200', function (error, data, res) {
   should.ok(!error);
   data.should.be.an.instanceof(Buffer);
   res.statusCode.should.eql(200);
   done();
 });
 .expect((res) => {
   should.ok(res.body.payment)
   should.equal(res.body.payment.amount, 71 * 100)
 })
示例#8
0
文件: index_test.js 项目: abdula/edom
 it('should create new instance', function() {
     should.ok(typeof EDom === 'function');
     var edom =  new EDom(defOpts);
     edom.should.be.an.instanceOf(EDom);
 });
  it('should run a multi run job a correct number of times', function() {
    var task = { 'Test ID': '121106_WK_M', runs: 3 };

    test_utils.stubLog(sandbox, function(
         levelPrinter, levelName, stamp, source, message) {
      return message.match(new RegExp('Finished\\srun\\s\\d+/' +
          task.runs + '\\s(.*\\s)?of\\sjob\\s' + task['Test ID'] +
          '(\\s|$)'));
    });

    var numJobRuns = 0;

    var client = new wpt_client.Client(app, {serverUrl: 'url',
        location: 'test'});
    var doneSpy = sandbox.spy();
    client.on('done', doneSpy);

    // This flag flips back and forth to simulate "repeat view" runs --
    // they submit a set of results, but do not increment the run number.
    // So overall we will do 6 runs -- 2 runs * 3 iterations.
    // Each run calls runFinished with false and then true. The initial value
    // is true because we flip it right before calling runFinished.
    var isRunFinished = true;
    var expectedRunNumber = 0;
    client.onStartJobRun = function(job) {
      logger.debug('Stub start run %d/%d', job.runNumber, job.runs);
      numJobRuns += 1;
      // Simulate an async runFinished() call as in the real system.
      global.setTimeout(function() {
        isRunFinished = !isRunFinished;
        if (!isRunFinished) {
          expectedRunNumber += 1;
        }
        should.equal(expectedRunNumber, job.runNumber);
        job.runFinished(isRunFinished);
      }, 0);
    };

    test_utils.stubHttpGet(sandbox, /\/work\/getwork/, JSON.stringify(task));

    // Stub a POST
    var postResponse = new Stream();
    postResponse.setEncoding = function() {};
    sandbox.stub(http, 'request',
        function(options, responseCb) {
      logger.debug('Stub POST http://%s:%s%s',
          options.host, options.port, options.path);
      options.path.should.match(/\/work\/workdone/);
      responseCb(postResponse);
      return {  // Fake request object
        'end': function(/*body, encoding*/) {
          postResponse.emit('end');  // No data in the response
        },
        'on': function() {}
      };
    });

    client.run(/*forever=*/false);
    sandbox.clock.tick(10);
    should.ok(doneSpy.calledOnce);
    should.equal(6, numJobRuns);
  });
示例#10
0
var assertIdentity = function (transform) {
  should.ok(transform.equals(IDENTITY))
}
示例#11
0
 factory.exists("/test", function(err, exists) {
   should.not.exists(err);
   should.ok(exists);
   done();
 });
示例#12
0
 ProcessIds(__dirname + '/fixtures/echo.js', function(error, ids) {
   should.ok(!error);
   ids.should.have.property('length', 0);
   done();
 });
示例#13
0
 fs.readFile(pidfile, 'utf-8', function(error, data) {
   should.ok(!error);
   parseInt(data, 10).should.eql(process.pid);
   done();
 });
示例#14
0
 urllib.request('https://www.alipay.com/', {timeout: 10000}, function (err, data, res) {
   should.not.exist(err);
   should.ok(Buffer.isBuffer(data));
   res.should.status(200);
   done();
 });
示例#15
0
 it('should revert correctly', function() {
   MockDate.reset();
   should.equal(new Date().getFullYear(), currentYear);
   should.ok(Date.toString().indexOf('native'));
 });
  it('should start and stop video recording', function() {
    var serial = 'GAGA123';
    var pid = 7;

    var fakeCaptureProc;
    var killCount = 0;
    var processSpawnStub = test_utils.stubOutProcessSpawn(sandbox);
    processSpawnStub.callback = function(proc, command, args) {
      if (videoCommand === command) {
        proc.pid = pid;
        fakeCaptureProc = proc;
        return true; // keep alive
      }
      var stdout;
      if ('ps' === command) {
        stdout = [
          '1 ' + pid + ' ' + videoCommand + ' -f x -s ' + serial + ' y',
          '1 ' + (pid + 100) + ' ignoreMe',
          pid + ' ' + (pid + 10) + ' raw_capture'
        ].join('\n');
      } else if ('kill' === command) {
        if (pid === parseInt(args[args.length - 1], 10) && fakeCaptureProc) {
          fakeCaptureProc.emit('exit', undefined, 'SIGAGA');
          fakeCaptureProc = undefined;
        }
        killCount += 1;
        stdout = '';
      } else {
        should.fail('Unexpected command: ' + command);
      }
      if (undefined !== stdout) {
        global.setTimeout(function() {
          proc.stdout.emit('data', stdout);
        }, 1);
      }
    };
    // Check for existence of the video record script
    var fsExistsStub = sandbox.stub(fs, 'exists', function(path, cb) {
      global.setTimeout(function() {
        cb(videoCommand === path);
      }, 1);
    });

    should.equal('[]', app.getSchedule());
    var videoFile = 'test.avi';
    var deviceType = 'shmantra';
    var videoCard = '2';

    var video = new video_hdmi.VideoHdmi(app, videoCommand);
    should.equal('[]', app.getSchedule());
    video.scheduleStartVideoRecording(videoFile, serial, deviceType, videoCard);
    sandbox.clock.tick(webdriver.promise.ControlFlow.EVENT_LOOP_FREQUENCY * 30);
    should.equal('[]', app.getSchedule());
    should.equal(2, killCount);
    processSpawnStub.assertCalls(
        {0: 'ps', 1: '-u', 2: /^\d+$/}, // Find our leftover capture pid
        {0: 'ps', 1: '-u', 2: /^\d+$/}, // Get the pid tree
        ['kill', '-9', ('' + pid)],
        ['kill', '-9', ('' + (pid + 10))],
        [videoCommand, '-f', videoFile, '-s', serial, '-t', deviceType, '-d',
            videoCard, '-w']);
    should.ok(fsExistsStub.calledOnce);

    // Watch for IDLE -- make sure the wait for recording exit has finished.
    var idleSpy = sandbox.spy();
    app.on(webdriver.promise.ControlFlow.EventType.IDLE, idleSpy);
    should.equal('[]', app.getSchedule());
    video.scheduleStopVideoRecording();
    sandbox.clock.tick(webdriver.promise.ControlFlow.EVENT_LOOP_FREQUENCY * 20);
    should.equal('[]', app.getSchedule());
    processSpawnStub.assertCalls(
        {0: 'ps'},
        ['kill', '-9', ('' + pid)],
        ['kill', '-9', ('' + (pid + 10))]);
    should.equal(4, killCount);
    should.equal(undefined, fakeCaptureProc);
    processSpawnStub.assertCall();
    should.ok(idleSpy.calledOnce);
  });
 csvextractor.extract([body], { silent: true }, function (err, bodyRecords) {
   should.ok(err === null);
   should.ok(helpers.equalJSONList(bodyRecords, correctRecords, true, ['status', 'size']),
     'The response of the server does not match the expected one');
   done();
 });
  it('should work overall with WD - start, run, stop', function() {
    // This is a long test that does a full run twice. It goes like this:
    // * General stubs/fakes/spies.
    // * Run 1 -- exitWhenDone=false.
    // * Verify after run 1, make sure we didn't quit/stop WD.
    // * Run 2 -- exitWhenDone=true.
    // * Verify after run 2, make sure we did quit+stop WD.
    //
    // We do this as a single test, because the WebDriverServer state after
    // the first run is crucial for the second run, and because some of the
    // stubs/spies remain the same from the first run into the second run.

    // * General stubs/fakes/spies.
    var chromedriver = '/gaga/chromedriver';

    // Stub out spawning chromedriver, verify at the end.
    var isFirstRun = true;
    var launcherStubs = stubWdLauncher(function() {
      should.ok(isFirstRun);  // Only spawn WD on first run.
    });
    var startWdServerStub = launcherStubs.startWdServerStub;
    var killStub = launcherStubs.killStub;
    // Stub out IPC, verify at the end.
    var sendStub = sandbox.stub(wd_server.process, 'send');
    var disconnectStub = sandbox.stub(wd_server.process, 'disconnect');

    stubServerReadyHttp();

    // Connect DevTools
    test_utils.stubHttpGet(sandbox, /^http:\/\/localhost:\d+\/json$/,
        '[{"webSocketDebuggerUrl": "ws://gaga"}]');
    var stubWebSocket = sandbox.stub(devtools, 'WebSocket', FakeWebSocket);
    var fakeWs;  // Assign later, after DevTools connection creates a WebSocket.

    // Fake a WebDriver instance, stub Builder.build() to return it.
    var driverQuitSpy = sinon.spy();
    var fakeDriver = {
      quit: function() {
        return app.schedule('Fake WebDriver.quit()', driverQuitSpy);
      }
    };
    var wdBuildStub = sandbox.stub(webdriver.Builder.prototype, 'build',
        function() {
      logger.debug('Stub Builder.build() called');
      return fakeDriver;
    });

    // Simulate Chrome generating profiling messages as the page loads.
    var pageMessage = {method: 'Page.gaga'};
    var networkMessage = {method: 'Network.ulala'};
    var timelineMessage = {method: 'Timeline.tutu'};
    // wd_server ignores DevTools messages before onDriverBuild actions finish.
    // Schedule our emission function after the onDriverBuild-scheduled stuff.
    var realOnDriverBuild = wds.onDriverBuild.bind(wds);
    var onBuildStub = sandbox.stub(wds, 'onDriverBuild',
        function(driver, browserCaps, wdNamespace) {
          try {
            realOnDriverBuild.call(this, driver, browserCaps, wdNamespace);
          } catch (e) {
            logger.error('onDriverBuild failed:' + e.stack);
            throw e;
          }
          this.app_.schedule('Emit test DevTools events', function() {
            fakeWs.emit('message', JSON.stringify(pageMessage), {});
            fakeWs.emit('message', JSON.stringify(networkMessage), {});
            fakeWs.emit('message', JSON.stringify(timelineMessage), {});
          });
        });

    var idleSpy = sandbox.spy();
    app.on(webdriver.promise.Application.EventType.IDLE, idleSpy);

    // * Run 1 -- exitWhenDone=false.
    logger.debug('First run of WD server');
    wd_server.process.emit('message', {
        cmd: 'run',
        exitWhenDone: false,
        filePrefix: '1_Cached_',
        chromedriver: chromedriver,
        script: 'new webdriver.Builder().build();'
      });
    sandbox.clock.tick(wd_server.WAIT_AFTER_ONLOAD_MS +
        webdriver.promise.Application.EVENT_LOOP_FREQUENCY * 10);
    fakeWs = stubWebSocket.firstCall.thisValue;  // The DevTools WebSocket.
    fakeWs.emit('open');  // DevTools WebSocket connected.

    sandbox.clock.tick(wd_server.WAIT_AFTER_ONLOAD_MS +
        webdriver.promise.Application.EVENT_LOOP_FREQUENCY * 20 + 1000);
    onBuildStub.restore();  // Remove fake DevTools event emission.

    // * Verify after run 1, make sure we didn't quit/stop WD.
    // Should spawn the chromedriver process on port 4444.
    should.ok(startWdServerStub.calledOnce);
    should.equal('chrome', startWdServerStub.firstCall.args[0].browserName);

    should.ok(wdBuildStub.calledOnce);
    should.ok(stubWebSocket.calledOnce);
    should.ok('ws://gaga', stubWebSocket.firstCall.args[0]);
    [
        'Network.enable',
        'Page.enable',
        'Timeline.start',
        'Network.clearBrowserCache',
        'Network.clearBrowserCookies',
        'Page.navigate', // to blank
        'Page.getResourceTree',
        'Page.setDocumentContent',
        'Page.captureScreenshot'
      ].should.eql(fakeWs.commands);
    fakeWs.commands = [];  // Reset for next run verification.
    should.ok(sendStub.calledOnce);
    var doneIpcMsg = sendStub.firstCall.args[0];
    should.equal(doneIpcMsg.cmd, 'done');
    [pageMessage, networkMessage, timelineMessage].should.eql(
        doneIpcMsg.devToolsMessages);

    // We are not supposed to clean up on the first run.
    should.ok(driverQuitSpy.notCalled);
    should.ok(killStub.notCalled);
    should.ok(disconnectStub.notCalled);

    // * Run 2 -- exitWhenDone=true.
    logger.debug('Second run of WD server');
    wd_server.process.emit('message', {
        cmd: 'run',
        exitWhenDone: true,
        filePrefix: '1_Cached_',
        chromedriver: chromedriver,
        script: 'new webdriver.Builder().build();'
      });
    sandbox.clock.tick(wd_server.WAIT_AFTER_ONLOAD_MS +
        webdriver.promise.Application.EVENT_LOOP_FREQUENCY * 20);

    // * Verify after run 2, make sure we did quit+stop WD.
    // Make sure we did not spawn the WD server etc. for the second time.
    should.ok(startWdServerStub.calledOnce);
    should.ok(wdBuildStub.calledOnce);
    should.ok(stubWebSocket.calledOnce);

    // These things get called for the second time on the second run.
    ['Page.captureScreenshot'].should.eql(fakeWs.commands);
    should.ok(sendStub.calledTwice);
    doneIpcMsg = sendStub.secondCall.args[0];
    should.equal(doneIpcMsg.cmd, 'done');
    [].should.eql(doneIpcMsg.devToolsMessages);

    // The cleanup occurs only on the second run.
    should.ok(driverQuitSpy.calledOnce);
    should.ok(killStub.calledOnce);
    should.ok(disconnectStub.calledOnce);
  });
示例#19
0
 urllib.request('https://dn-abc.qbox.me/1.txt', {timeout: 10000}, function (err, data, res) {
   should.not.exist(err);
   should.ok(Buffer.isBuffer(data));
   res.should.status(200);
   done();
 });
  it('should work overall with Chrome - start, run, stop', function() {
    // This is a long test that does a full run twice. It goes like this:
    // * General stubs/fakes/spies.
    // * Run 1 -- exitWhenDone=false.
    // * Verify after run 1, make sure we didn't quit/stop WD.
    // * Run 2 -- exitWhenDone=true.
    // * Verify after run 2, make sure we did quit+stop WD.
    //
    // We do this as a single test, because the WebDriverServer state after
    // the first run is crucial for the second run, and because some of the
    // stubs/spies remain the same from the first run into the second run.

    // * General stubs/fakes/spies.
    var chromedriver = '/gaga/chromedriver';

    // Stub out spawning chromedriver, verify at the end.
    var isFirstRun = true;
    var launcherStubs = stubWdLauncher(function() {
      should.ok(isFirstRun);  // Only spawn WD on first run.
    });
    var startChromeStub = launcherStubs.startChromeStub;
    var killStub = launcherStubs.killStub;
    // Stub out IPC, verify at the end.
    var sendStub = sandbox.stub(wd_server.process, 'send');
    var disconnectStub = sandbox.stub(wd_server.process, 'disconnect');

    // Connect DevTools
    test_utils.stubHttpGet(sandbox, /^http:\/\/localhost:\d+\/json$/,
        '[{"webSocketDebuggerUrl": "ws://gaga"}]');
    var stubWebSocket = sandbox.stub(devtools, 'WebSocket', FakeWebSocket);

    var idleSpy = sandbox.spy();
    app.on(webdriver.promise.Application.EventType.IDLE, idleSpy);

    // * Run 1 -- exitWhenDone=false.
    logger.debug('First run of WD server');
    wd_server.process.emit('message', {
        cmd: 'run',
        exitWhenDone: false,
        filePrefix: '1_Cached_',
        chromedriver: chromedriver,
        url: 'http://gaga.com/ulala'
      });
    sandbox.clock.tick(wd_server.WAIT_AFTER_ONLOAD_MS +
        webdriver.promise.Application.EVENT_LOOP_FREQUENCY * 10);
    var fakeWs = stubWebSocket.firstCall.thisValue;  // The DevTools WebSocket.
    fakeWs.emit('open');  // DevTools WebSocket connected.

    // Simulate Chrome generating profiling messages as the page loads.
    var pageMessage = {method: 'Page.gaga'};
    var networkMessage = {method: 'Network.ulala'};
    var timelineMessage = {method: 'Timeline.tutu'};
    var pageLoadedMessage = {method: 'Page.loadEventFired'};
    // Verify that messages get ignored before the page load starts
    fakeWs.emit('message', JSON.stringify(networkMessage), {});

    // Emit DevTools events after the test has started -- Page.navigate fired.
    function onPageNavigate(message) {
      if (/"method"\s*:\s*"Page.navigate"/.test(message)) {
        var m = message.match(/"url":"([^"]+)"/);
        var url = (m ? m[1] : '');
        if ('http://gaga.com/ulala' === url) {
          fakeWs.removeListener('message', onPageNavigate);  // Fire only once.
          fakeWs.emit('message', JSON.stringify(pageMessage), {});
          fakeWs.emit('message', JSON.stringify(networkMessage), {});
          fakeWs.emit('message', JSON.stringify(timelineMessage), {});
          fakeWs.emit('message', JSON.stringify(pageLoadedMessage), {});
        } else {
          url.should.match(/^data:text/); // ignore blank
        }
      }
    }
    fakeWs.on('message', onPageNavigate);
    sandbox.clock.tick(wd_server.WAIT_AFTER_ONLOAD_MS +
        webdriver.promise.Application.EVENT_LOOP_FREQUENCY * 30 + 1000);

    // * Verify after run 1, make sure we didn't quit/stop Chrome.
    should.ok(startChromeStub.calledOnce);
    should.equal('chrome', startChromeStub.firstCall.args[0].browserName);

    should.ok(stubWebSocket.calledOnce);
    should.ok('ws://gaga', stubWebSocket.firstCall.args[0]);
    [
        'Network.enable',
        'Page.enable',
        'Timeline.start',
        'Network.clearBrowserCache',
        'Network.clearBrowserCookies',
        'Page.navigate', // to blank
        'Page.getResourceTree',
        'Page.setDocumentContent',
        'Page.navigate',
        'Page.captureScreenshot'
      ].should.eql(fakeWs.commands);
    fakeWs.commands = [];  // Reset for the next verification.
    should.ok(sendStub.calledOnce);
    var doneIpcMsg = sendStub.firstCall.args[0];
    should.equal(doneIpcMsg.cmd, 'done');
    [pageMessage, networkMessage, timelineMessage,
        pageLoadedMessage].should.eql(doneIpcMsg.devToolsMessages);

    // We are not supposed to clean up on the first run.
    should.ok(killStub.notCalled);
    should.ok(disconnectStub.notCalled);

    // * Run 2 -- exitWhenDone=true.
    logger.debug('Second run of WD server');
    wd_server.process.emit('message', {
        cmd: 'run',
        exitWhenDone: true,
        filePrefix: '1_Cached_',
        chromedriver: chromedriver,
        url: 'http://gaga.com/ulala'
      });
    // Verify that messages get ignored between runs
    fakeWs.emit('message', JSON.stringify(networkMessage), {});
    sandbox.clock.tick(wd_server.WAIT_AFTER_ONLOAD_MS +
        webdriver.promise.Application.EVENT_LOOP_FREQUENCY * 20 + 1000);
    // Simulate page load finish.
    fakeWs.emit('message', JSON.stringify(pageLoadedMessage), {});
    sandbox.clock.tick(webdriver.promise.Application.EVENT_LOOP_FREQUENCY * 20);

    // * Verify after run 2, make sure we did quit+stop Chrome.
    // Make sure we did not spawn Chrome or connect DevTools repeatedly.
    should.ok(startChromeStub.calledOnce);
    should.ok(stubWebSocket.calledOnce);

    // These things get called for the second time on the second run.
    [
        'Page.navigate', // to blank
        'Page.getResourceTree',
        'Page.setDocumentContent',
        'Page.navigate',
        'Page.captureScreenshot'
      ].should.eql(fakeWs.commands);
    should.ok(sendStub.calledTwice);
    doneIpcMsg = sendStub.secondCall.args[0];
    should.equal(doneIpcMsg.cmd, 'done');
    [pageLoadedMessage].should.eql(doneIpcMsg.devToolsMessages);

    // The cleanup occurs only on the second run.
    should.ok(killStub.calledOnce);
    should.ok(disconnectStub.calledOnce);
  });
 .expect((res) => {
   should.ok(res.body.paid)
   paid = res.body.paid
 })
 var launcherStubs = stubWdLauncher(function() {
   should.ok(isFirstRun);  // Only spawn WD on first run.
 });
示例#23
0
 var board = new Board(serialPort, options, function(err) {
   should.deepEqual(serialPort.lastWrite, [ 240, 122, 100, 0, 247 ]);
   should.equal(spy.callCount, 1);
   should.ok(spy.calledWith(100));
   done();
 });
示例#24
0
 it('should be awesome', function () {
   assert.ok(true);
 });
示例#25
0
 it('test remove all', function () {
   Table.removeAllSync({age: ['>', 10]});
   should.ok(Table.query().execSync().length === 0);
 });
示例#26
0
文件: mm.test.js 项目: alsotang/mm
 res.on('data', function (chunk) {
   should.ok(Buffer.isBuffer(chunk));
   body += chunk.toString();
 });
示例#27
0
 it('test find all none exist', function () {
   records = Table.query({age: ['>', 10]}).execSync();
   should.ok(records.length === 0);
 });
示例#28
0
 it('should allow mock dates to show up as real dates using instanceof', function() {
   should.ok(new Date() instanceof Date);
 });
示例#29
0
 h.driver.execute("mobile: background", [{seconds: 1}], function(err) {
   should.not.exist(err);
   var after = new Date().getTime() / 1000;
   should.ok((after - before) <= 10);
   done();
 });
示例#30
0
 it('client.getImages should have minimum 1 argument', function () {
   client.getImages.should.be.a.Function;
   should.ok(client.getImages.length >= 1);
 });