Repository: parcel-bundler/parcel
File: packages/core/core/test/ParcelConfig.test.js (JavaScript)

Code before:
          filePath: configFilePath,
          bundler: undefined,
          transformers: {
            '*.js': [
              {
                packageName: 'parcel-transformer-no-engines',
                resolveFrom: configFilePath,
                keyPath: '/transformers/*.js/0',
              },
            ],
          },
        },
        DEFAULT_OPTIONS,
      );

      sinon.stub(logger, 'warn');
      let {plugin} = await config.loadPlugin({
        packageName: 'parcel-transformer-no-engines',
        resolveFrom: configFilePath,
        keyPath: '/transformers/*.js/0',
      });
      assert(plugin);
      assert.equal(typeof plugin.transform, 'function');
      // $FlowFixMe[method-unbinding]
      assert(logger.warn.calledOnce);
      // $FlowFixMe[method-unbinding]
      assert.deepEqual(logger.warn.getCall(0).args[0], {
        origin: '@parcel/core',
        message:
          'The plugin "parcel-transformer-no-engines" needs to specify a `package.json#engines.parcel` field with the supported Parcel version range.',
      });
      // $FlowFixMe[method-unbinding]
      logger.warn.restore();
    });

    it('should error if a plugin specifies an invalid engines.parcel field in package.json', async () => {
      let configFilePath = path.join(
        __dirname,
        'fixtures',
        'plugins',
        '.parcelrc',
      );
      let config = new ParcelConfig(
        {
          filePath: configFilePath,
          bundler: undefined,
          transformers: {
            '*.js': [
              {
                packageName: 'parcel-transformer-not-found',
                resolveFrom: configFilePath,

Review comment (suggestion):
I think this can be avoided by doing something like this (above):

```js
let warnStub = sinon.stub(logger, 'warn');
// ... config.loadPlugin()
assert(warnStub.getCall(0).args[0], ...)
```

Code after:
          filePath: configFilePath,
          bundler: undefined,
          transformers: {
            '*.js': [
              {
                packageName: 'parcel-transformer-no-engines',
                resolveFrom: configFilePath,
                keyPath: '/transformers/*.js/0',
              },
            ],
          },
        },
        DEFAULT_OPTIONS,
      );

      let warnStub = sinon.stub(logger, 'warn');
      let {plugin} = await config.loadPlugin({
        packageName: 'parcel-transformer-no-engines',
        resolveFrom: configFilePath,
        keyPath: '/transformers/*.js/0',
      });
      assert(plugin);
      assert.equal(typeof plugin.transform, 'function');
      assert(warnStub.calledOnce);
      assert.deepEqual(warnStub.getCall(0).args[0], {
        origin: '@parcel/core',
        message:
          'The plugin "parcel-transformer-no-engines" needs to specify a `package.json#engines.parcel` field with the supported Parcel version range.',
      });
      warnStub.restore();
    });

    it('should error if a plugin specifies an invalid engines.parcel field in package.json', async () => {
      let configFilePath = path.join(
        __dirname,
        'fixtures',
        'plugins',
        '.parcelrc',
      );
      let config = new ParcelConfig(
        {
          filePath: configFilePath,
          bundler: undefined,
          transformers: {
            '*.js': [
              {
                packageName: 'parcel-transformer-not-found',
                resolveFrom: configFilePath,
                keyPath: '/transformers/*.js/0',
              },
            ],