Repository: parcel-bundler/parcel
File: packages/core/integration-tests/test/fs.js (JavaScript)

Code before:
      await assert.rejects(() => run(b), /\.readFileSync is not a function/);
    });
  });

  describe('node environment', function () {
    it('should not inline a file in a node environment', async function () {
      let b = await bundle(
        path.join(__dirname, '/integration/fs-node/index.js'),
      );

      assertBundles(b, [
        {
          name: 'index.js',
          assets: ['index.js'],
        },
      ]);

      let contents = await outputFS.readFile(
        path.join(distDir, 'index.js'),
        'utf8',
      );
      assert(contents.includes("require('fs')"));
      assert(contents.includes('readFileSync'));

      let output = await run(b);
      assert.equal(output, 'hello');
    });
  });

  describe.skip('electron environment', function () {
    it('should not inline a file in an Electron environment', async function () {
      let b = await bundle(path.join(__dirname, '/integration/fs/index.js'), {
        targets: ['electron'],
      });

      assertBundles(b, [
        {
          name: 'index.js',
          assets: ['index.js'],
        },
      ]);

      let contents = await outputFS.readFile(
        path.join(distDir, 'index.js'),
        'utf8',
      );
      assert(contents.includes("require('fs')"));
      assert(contents.includes('readFileSync'));

      await outputFS.writeFile(path.join(distDir, 'test.txt'), 'hey');
      let output = await run(b);

Review comment (suggestion):
Previously this was creating a new file in the distDir because the compiled code still had `__dirname` in it which resolved to the distDir. Now it points to the original directory so creating a new file is not necessary (the original file has "hello" in it)

Code after:
      await assert.rejects(() => run(b), /\.readFileSync is not a function/);
    });
  });

  describe('node environment', function () {
    it('should not inline a file in a node environment', async function () {
      let b = await bundle(
        path.join(__dirname, '/integration/fs-node/index.js'),
      );

      assertBundles(b, [
        {
          name: 'index.js',
          assets: ['index.js'],
        },
      ]);

      let contents = await outputFS.readFile(
        path.join(distDir, 'index.js'),
        'utf8',
      );
      assert(contents.includes("require('fs')"));
      assert(contents.includes('readFileSync'));

      await outputFS.writeFile(
        path.join(__dirname, '/integration/fs-node/', 'test.txt'),
        'hey',
      );
      let output = await run(b);
      assert.equal(output, 'hey');
    });
  });

  describe.skip('electron environment', function () {
    it('should not inline a file in an Electron environment', async function () {
      let b = await bundle(path.join(__dirname, '/integration/fs/index.js'), {
        targets: ['electron'],
      });

      assertBundles(b, [
        {
          name: 'index.js',
          assets: ['index.js'],
        },
      ]);

      let contents = await outputFS.readFile(
        path.join(distDir, 'index.js'),
        'utf8',
      );
      assert(contents.includes("require('fs')"));