• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright Joyent, Inc. and other Node contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to permit
8// persons to whom the Software is furnished to do so, subject to the
9// following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22'use strict';
23const common = require('../common');
24const assert = require('assert');
25const child = require('child_process');
26const fixtures = require('../common/fixtures');
27
28if (!common.isMainThread)
29  common.skip('process.chdir is not available in Workers');
30
31if (process.env.TEST_INIT) {
32  return process.stdout.write('Loaded successfully!');
33}
34
35process.env.TEST_INIT = 1;
36
37function test(file, expected) {
38  const path = `"${process.execPath}" ${file}`;
39  child.exec(path, { env: process.env }, common.mustSucceed((out) => {
40    assert.strictEqual(out, expected, `'node ${file}' failed!`);
41  }));
42}
43
44{
45  // Change CWD as we do this test so it's not dependent on current CWD
46  // being in the test folder
47  process.chdir(__dirname);
48  test('test-init', 'Loaded successfully!');
49  test('test-init.js', 'Loaded successfully!');
50}
51
52{
53  // test-init-index is in fixtures dir as requested by ry, so go there
54  process.chdir(fixtures.path());
55  test('test-init-index', 'Loaded successfully!');
56}
57
58{
59  // Ensures that `node fs` does not mistakenly load the native 'fs' module
60  // instead of the desired file and that the fs module loads as
61  // expected in node
62  process.chdir(fixtures.path('test-init-native'));
63  test('fs', 'fs loaded successfully');
64}
65