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

Code before:
        let assets = Array.from(event.changedAssets.values());
        // should contain all the assets
        assertChangedAssets(getChangedAssetsBeforeRuntimes(assets).length, 3);
        // the default bundler was only called once
        assertTimesBundled(defaultBundlerSpy.callCount, 1);
        // calls the new bundler to rebundle
        assertTimesBundled(customBundlerSpy.callCount, 1);

        let output = await overlayFS.readFile(
          path.join(fixture, 'index.js'),
          'utf8',
        );
        assert(output.includes(`import {a} from './a'`));
      } finally {
        if (subscription) {
          await subscription.unsubscribe();
          subscription = null;
        }
      }
    });

    it('changing bundler options', async () => {
      let subscription;
      let fixture = path.join(__dirname, '/integration/incremental-bundling');
      try {
        let b = bundler(path.join(fixture, 'index.js'), {
          inputFS: overlayFS,
          shouldDisableCache: false,
          shouldBundleIncrementally: true,
        });

        await overlayFS.mkdirp(fixture);
        subscription = await b.watch();

        let event = await getNextBuildSuccess(b);
        assertTimesBundled(defaultBundlerSpy.callCount, 1);

        let pkgFile = path.join(fixture, 'package.json');
        let pkg = JSON.parse(await overlayFS.readFile(pkgFile));
        await overlayFS.writeFile(
          pkgFile,
          JSON.stringify({
            ...pkg,
            '@parcel/bundler-default': {
              http: 1,
            },
          }),
        );

        event = await getNextBuildSuccess(b);


Review comment (bug):
I migrated this test as it was incorrectly sending file `create` events rather than `update` events causing the config to not invalidate. This is a bug when using overlayFS with a normal read FS but an in memory write FS.  

Code after:
        event = await getNextBuildSuccess(b);
        let assets = Array.from(event.changedAssets.values());
        // should contain all the assets
        assertChangedAssets(getChangedAssetsBeforeRuntimes(assets).length, 3);
        // the default bundler was only called once
        assertTimesBundled(defaultBundlerSpy.callCount, 1);
        // calls the new bundler to rebundle
        assertTimesBundled(customBundlerSpy.callCount, 1);

        let output = await overlayFS.readFile(
          path.join(fixture, 'index.js'),
          'utf8',
        );
        assert(output.includes(`import {a} from './a'`));
      } finally {
        if (subscription) {
          await subscription.unsubscribe();
          subscription = null;
        }
      }
    });

    it('changing bundler options', async () => {
      let subscription;
      try {
        await fsFixture(overlayFS, __dirname)`
          index.js:
            export default 1;

          package.json:
            {
              "@parcel/bundler-default": {
                "http": 2
              }
            }

          yarn.lock:`;

        let b = bundler(path.join(__dirname, 'index.js'), {
          inputFS: overlayFS,
          shouldDisableCache: false,
          shouldBundleIncrementally: true,
        });

        await overlayFS.mkdirp(__dirname);
        subscription = await b.watch();

        let event = await getNextBuildSuccess(b);
        assertTimesBundled(defaultBundlerSpy.callCount, 1);

        let pkgFile = path.join(__dirname, 'package.json');