~webapps/unity-js-scopes/node.js

« back to all changes in this revision

Viewing changes to test/sequential/test-init.js

  • Committer: Marcus Tomlinson
  • Date: 2015-11-13 07:59:04 UTC
  • Revision ID: marcus.tomlinson@canonical.com-20151113075904-h0swczmoq1rvstfc
Node v4 (stable)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'use strict';
 
2
(function() {
 
3
  var assert = require('assert'),
 
4
      child = require('child_process'),
 
5
      util = require('util'),
 
6
      common = require('../common');
 
7
  if (process.env['TEST_INIT']) {
 
8
    util.print('Loaded successfully!');
 
9
  } else {
 
10
    // change CWD as we do this test so its not dependant on current CWD
 
11
    // being in the test folder
 
12
    process.chdir(__dirname);
 
13
 
 
14
    // slow but simple
 
15
    var envCopy = JSON.parse(JSON.stringify(process.env));
 
16
    envCopy.TEST_INIT = 1;
 
17
 
 
18
    child.exec('"' + process.execPath + '" test-init', {env: envCopy},
 
19
        function(err, stdout, stderr) {
 
20
          assert.equal(stdout, 'Loaded successfully!',
 
21
                       '`node test-init` failed!');
 
22
        });
 
23
    child.exec('"' + process.execPath + '" test-init.js', {env: envCopy},
 
24
        function(err, stdout, stderr) {
 
25
          assert.equal(stdout, 'Loaded successfully!',
 
26
                       '`node test-init.js` failed!');
 
27
        });
 
28
 
 
29
    // test-init-index is in fixtures dir as requested by ry, so go there
 
30
    process.chdir(common.fixturesDir);
 
31
 
 
32
    child.exec('"' + process.execPath + '" test-init-index', {env: envCopy},
 
33
        function(err, stdout, stderr) {
 
34
          assert.equal(stdout, 'Loaded successfully!',
 
35
                       '`node test-init-index failed!');
 
36
        });
 
37
 
 
38
    // ensures that `node fs` does not mistakenly load the native 'fs' module
 
39
    // instead of the desired file and that the fs module loads as
 
40
    // expected in node
 
41
    process.chdir(common.fixturesDir + '/test-init-native/');
 
42
 
 
43
    child.exec('"' + process.execPath + '" fs', {env: envCopy},
 
44
        function(err, stdout, stderr) {
 
45
          assert.equal(stdout, 'fs loaded successfully',
 
46
                       '`node fs` failed!');
 
47
        });
 
48
  }
 
49
})();