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

Code before:
            loadConfig({config, options}) {
              return DefaultBundler[CONFIG].loadConfig({config, options});
            },
          
            bundle({bundleGraph, config}) {
              DefaultBundler[CONFIG].bundle({bundleGraph, config});
            },
            optimize() {throw new Error("Intentionally throw error")},
          });
        yarn.lock:`;
      // $FlowFixMe
      await assert.rejects(() => bundle(entries, options));

      let resolvedOptions = await resolveOptions(
        getParcelOptions(entries, options),
      );

      let bundleGraphCacheKey = hashString(
        `${version}:BundleGraph:${
          JSON.stringify(resolvedOptions.entries) ?? ''
        }${resolvedOptions.mode}`,
      );

      let bundleGraphPath = path.join(
        resolvedOptions.cacheDir,
        bundleGraphCacheKey + '-0',
      );

      assert(v8.deserialize(overlayFS.readFileSync(bundleGraphPath)));
    });

    it('should invalidate when a terser config is modified', async function () {
      let b = await testCache({
        mode: 'production',
        async setup() {
          await overlayFS.writeFile(
            path.join(inputDir, '.terserrc'),
            JSON.stringify({
              mangle: false,
            }),
          );
        },
        async update(b) {
          let contents = await overlayFS.readFile(
            b.bundleGraph.getBundles()[0].filePath,
            'utf8',
          );
          assert(contents.includes('$parcel$interopDefault'));

          await overlayFS.writeFile(
            path.join(inputDir, '.terserrc'),

Review comment (performance):
Not sure if this is the best way to determine the bundleGraphPath. Currently being determined [here ](https://github.com/parcel-bundler/parcel/blob/817c7786ef57bfd4810fbcb791c2eb90c78bcbc2/packages/core/cache/src/FSCache.js#L110). Which means if that changes, this code will break, but I have no way of accessing this function directly, so this is currently hardcoded.

Code after:
            loadConfig({config, options}) {
              return DefaultBundler[CONFIG].loadConfig({config, options});
            },
          
            bundle({bundleGraph, config}) {
              DefaultBundler[CONFIG].bundle({bundleGraph, config});
            },
            optimize() {throw new Error("Intentionally throw error")},
          });
        yarn.lock:`;
      // $FlowFixMe
      await assert.rejects(() => bundle(entries, options));

      let resolvedOptions = await resolveOptions(
        getParcelOptions(entries, options),
      );

      let bundleGraphCacheKey = hashString(
        `${version}:BundleGraph:${
          JSON.stringify(resolvedOptions.entries) ?? ''
        }${resolvedOptions.mode}`,
      );

      assert(
        deserialize(
          await resolvedOptions.cache.getLargeBlob(bundleGraphCacheKey),
        ),
      );
    });

    it('should invalidate when a terser config is modified', async function () {
      let b = await testCache({
        mode: 'production',
        async setup() {
          await overlayFS.writeFile(
            path.join(inputDir, '.terserrc'),
            JSON.stringify({
              mangle: false,
            }),
          );
        },
        async update(b) {
          let contents = await overlayFS.readFile(
            b.bundleGraph.getBundles()[0].filePath,
            'utf8',
          );
          assert(contents.includes('$parcel$interopDefault'));

          await overlayFS.writeFile(
            path.join(inputDir, '.terserrc'),
            JSON.stringify({