function validateBundle (expectedBundleStructure, bundle) {
  const originalWarn = console.warn

  console.warn = function (...args) {
    if (args.join(' ').includes('is moved to') && args.join(' ').includes('Please use the new location instead')) {
      // Ignore warnings like:
      // Warning: math.type.isNumber is moved to math.isNumber in v6.0.0. Please use the new location instead.
      return
    }

    originalWarn.apply(console, args)
  }

  try {
    const issues = []

    // see whether all expected functions and objects are there
    traverse(expectedBundleStructure, (expectedType, path) => {
      const actualValue = get(bundle, path)
      const actualType = validateTypeOf(actualValue)

      const message = (actualType === 'undefined')
        ? 'Missing entry in bundle. ' +
        `Path: ${JSON.stringify(path)}, expected type: ${expectedType}, actual type: ${actualType}`
        : 'Unexpected entry type in bundle. ' +
        `Path: ${JSON.stringify(path)}, expected type: ${expectedType}, actual type: ${actualType}`

      if (actualType !== expectedType) {
        issues.push({ actualType, expectedType, message })

        console.warn(message)
      }
    })

    // see whether there are any functions or objects that shouldn't be there
    traverse(bundle, (actualValue, path) => {
      const actualType = validateTypeOf(actualValue)
      const expectedType = get(expectedBundleStructure, path) || 'undefined'

      // FIXME: ugly to have these special cases
      if (path.join('.').includes('docs.')) {
        // ignore the contents of docs
        return
      }
      if (path.join('.').includes('all.')) {
        // ignore the contents of all dependencies
        return
      }

      const message = (expectedType === 'undefined')
        ? 'Unknown entry in bundle. ' +
        'Is there a new function added which is missing in this snapshot test? ' +
        `Path: ${JSON.stringify(path)}, expected type: ${expectedType}, actual type: ${actualType}`
        : 'Unexpected entry type in bundle. ' +
        `Path: ${JSON.stringify(path)}, expected type: ${expectedType}, actual type: ${actualType}`

      if (actualType !== expectedType) {
        issues.push({ actualType, expectedType, message })

        console.warn(message)
      }
    })

    // assert on the first issue (if any)
    if (issues.length > 0) {
      const { actualType, expectedType, message } = issues[0]

      console.warn(`${issues.length} bundle issues found`)

      assert.strictEqual(actualType, expectedType, message)
    }
  } finally {
    console.warn = originalWarn
  }
}
This file contains helper methods to create expected snapshot structures
of both instance and ES6 exports.

The files are located here and not under /test or /tools so it's transpiled
into ES5 code under /lib and can be used straight by node.js