test-node-os.js 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. let os = require("node/os");
  6. let system = require("sdk/system");
  7. exports["test os"] = function (assert) {
  8. assert.equal(os.tmpdir(), system.pathFor("TmpD"), "os.tmpdir() matches temp dir");
  9. assert.ok(os.endianness() === "BE" || os.endianness() === "LE", "os.endianness is BE or LE");
  10. assert.ok(os.arch().length > 0, "os.arch() returns a value");
  11. assert.equal(typeof os.arch(), "string", "os.arch() returns a string");
  12. assert.ok(os.type().length > 0, "os.type() returns a value");
  13. assert.equal(typeof os.type(), "string", "os.type() returns a string");
  14. assert.ok(os.platform().length > 0, "os.platform() returns a value");
  15. assert.equal(typeof os.platform(), "string", "os.platform() returns a string");
  16. assert.ok(os.release().length > 0, "os.release() returns a value");
  17. assert.equal(typeof os.release(), "string", "os.release() returns a string");
  18. assert.ok(os.hostname().length > 0, "os.hostname() returns a value");
  19. assert.equal(typeof os.hostname(), "string", "os.hostname() returns a string");
  20. assert.ok(os.EOL === "\n" || os.EOL === "\r\n", "os.EOL returns a correct EOL char");
  21. assert.deepEqual(os.loadavg(), [0, 0, 0], "os.loadavg() returns an array of 0s");
  22. ["uptime", "totalmem", "freemem", "cpus"].forEach(method => {
  23. assert.throws(() => os[method](), "os." + method + " throws");
  24. });
  25. };
  26. require("test").run(exports);