How to use md5-hex - 10 common examples

To help you get started, we’ve selected a few md5-hex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github novemberborn / hullabaloo-config-manager / test / Verifier.js View on Github external
const env = {}
  const main = requireWithCurrentEnv(env)
  const cache = main.prepareCache()
  const result = await main.fromConfig(main.createConfig({
    options: require(source), // eslint-disable-line import/no-dynamic-require
    source
  }), {cache})
  const verifier = await result.createVerifier()

  t.deepEqual(verifier.cacheKeysForEnv(), {
    dependencies: md5Hex([
      hashes[fixture('compare', 'node_modules', 'plugin-copy', 'package.json')],
      hashes[fixture('compare', 'node_modules', 'plugin', 'package.json')],
      hashes[fixture('compare', 'node_modules', 'preset', 'package.json')]
    ]),
    sources: md5Hex([
      hashes[fixture('compare', '.babelrc')],
      hashes[fixture('compare', 'dir', 'subdir', 'extended-by-babelrc.js')],
      hashes[fixture('compare', 'extended-by-virtual.json5')],
      hashes[fixture('compare', 'virtual.json')]
    ])
  })

  t.deepEqual(verifier.cacheKeysForEnv('foo'), {
    dependencies: md5Hex([
      hashes[fixture('compare', 'node_modules', 'env-plugin', 'package.json')],
      hashes[fixture('compare', 'node_modules', 'plugin-copy', 'package.json')],
      hashes[fixture('compare', 'node_modules', 'plugin-default-opts', 'package.json')],
      hashes[fixture('compare', 'node_modules', 'plugin', 'package.json')],
      hashes[fixture('compare', 'node_modules', 'preset', 'package.json')]
    ]),
    sources: md5Hex([
github novemberborn / hullabaloo-config-manager / test / hashSources.js View on Github external
test('hashes file contents', async t => {
  const source = fixture('babelrc', '.babelrc')
  const hashed = await hashSources([{source, runtimeHash: null}])
  t.deepEqual(hashed, [md5Hex(fs.readFileSync(source))])
})
github novemberborn / hullabaloo-config-manager / test / hashSources.js View on Github external
test('can use a cache for file access', async t => {
  const source = fixture('cached-access')
  const contents = Buffer.from('cached')
  const cache = prepareCache()
  cache.files.set(source, Promise.resolve(contents))

  const hashed = await hashSources([{source, runtimeHash: null}], null, cache)
  t.deepEqual(hashed, [md5Hex(contents)])
})
github novemberborn / hullabaloo-config-manager / test / main.js View on Github external
test('createConfig() can take a fixed hash for the options', async t => {
  const result = await fromConfig(createConfig({
    options: {
      babelrc: false
    },
    source: 'foo',
    hash: 'hash of foo'
  }))

  const verifier = await result.createVerifier()
  t.deepEqual(verifier.cacheKeysForEnv(), {
    dependencies: md5Hex([]),
    sources: md5Hex(['hash of foo'])
  })
})
github novemberborn / hullabaloo-config-manager / test / hashSources.js View on Github external
test('hashes the "babel" value in package.json sources', async t => {
  const sources = [
    fixture('pkg', 'package.json'),
    fixture('bad-pkg', 'array-babel', 'package.json'),
    fixture('bad-pkg', 'bool-babel', 'package.json'),
    fixture('bad-pkg', 'falsy', 'package.json'),
    fixture('bad-pkg', 'null', 'package.json'),
    fixture('bad-pkg', 'null-babel', 'package.json'),
    fixture('bad-pkg', 'without-babel', 'package.json')
  ].map(source => ({source, runtimeHash: null}))

  const hashed = await hashSources(sources)
  t.deepEqual(hashed, [
    md5Hex('{"plugins":["pkg"]}'),
    md5Hex('[]'),
    md5Hex('true'),
    md5Hex('{}'),
    md5Hex('{}'),
    md5Hex('{}'),
    md5Hex('{}')
  ])
})
github novemberborn / hullabaloo-config-manager / test / hashSources.js View on Github external
test('hashes the "babel" value in package.json sources', async t => {
  const sources = [
    fixture('pkg', 'package.json'),
    fixture('bad-pkg', 'array-babel', 'package.json'),
    fixture('bad-pkg', 'bool-babel', 'package.json'),
    fixture('bad-pkg', 'falsy', 'package.json'),
    fixture('bad-pkg', 'null', 'package.json'),
    fixture('bad-pkg', 'null-babel', 'package.json'),
    fixture('bad-pkg', 'without-babel', 'package.json')
  ].map(source => ({source, runtimeHash: null}))

  const hashed = await hashSources(sources)
  t.deepEqual(hashed, [
    md5Hex('{"plugins":["pkg"]}'),
    md5Hex('[]'),
    md5Hex('true'),
    md5Hex('{}'),
    md5Hex('{}'),
    md5Hex('{}'),
    md5Hex('{}')
  ])
})
github novemberborn / hullabaloo-config-manager / test / hashSources.js View on Github external
test('source may contain a dot-prop path', async t => {
  const source = fixture('virtual', 'package.json#deeply.nested')
  const hashed = await hashSources([{source, runtimeHash: null}])
  t.deepEqual(hashed, [md5Hex('{"virtual":true}')])
})
github novemberborn / hullabaloo-config-manager / test / hashDependencies.js View on Github external
test('hashes files', async t => {
  const filename = fixture('compare', 'node_modules', 'plugin', 'index.js')
  const hashed = await hashDependencies([
    {filename, fromPackage: null}
  ])
  t.deepEqual(hashed, [md5Hex(fs.readFileSync(filename))])
})
github novemberborn / hullabaloo-config-manager / test / Verifier.js View on Github external
fse.copySync(fixture('verifier', 'babelrc'), dir)

  const verifier = await (await fromDirectory(dir)).createVerifier()
  const cacheKeys = verifier.cacheKeysForEnv()

  t.deepEqual(await verifier.verifyEnv(), {
    sourcesChanged: false,
    dependenciesChanged: false,
    cacheKeys,
    verifier
  })

  {
    fs.writeFileSync(path.join(dir, 'plugin.js'), 'foo')
    const expectedCacheKeys = {
      dependencies: md5Hex([md5Hex('foo')]),
      sources: cacheKeys.sources
    }

    const result = await verifier.verifyEnv()
    const {verifier: newVerifier} = result
    delete result.verifier

    t.deepEqual(result, {
      sourcesChanged: false,
      dependenciesChanged: true,
      cacheKeys: expectedCacheKeys
    })
    t.true(newVerifier !== verifier)
    t.deepEqual(newVerifier.cacheKeysForEnv(), expectedCacheKeys)
  }
github novemberborn / hullabaloo-config-manager / test / Verifier.js View on Github external
fse.copySync(fixture('verifier', 'babelrc'), dir)

  const verifier = await (await fromDirectory(dir)).createVerifier()
  const cacheKeys = verifier.cacheKeysForEnv('foo')

  t.deepEqual(await verifier.verifyEnv('foo'), {
    sourcesChanged: false,
    dependenciesChanged: false,
    cacheKeys,
    verifier
  })

  {
    fs.writeFileSync(path.join(dir, 'foo.js'), 'foo')
    const expectedCacheKeys = {
      dependencies: md5Hex([md5Hex('foo'), md5Hex('module.exports = () => {}\n')]),
      sources: cacheKeys.sources
    }

    const result = await verifier.verifyEnv('foo')
    const {verifier: newVerifier} = result
    delete result.verifier

    t.deepEqual(result, {
      sourcesChanged: false,
      dependenciesChanged: true,
      cacheKeys: expectedCacheKeys
    })
    t.true(newVerifier !== verifier)
    t.deepEqual(newVerifier.cacheKeysForEnv('foo'), expectedCacheKeys)
  }

md5-hex

Create a MD5 hash with hex encoding

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis

Popular md5-hex functions