• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microlinkhq / metascraper / 5478073159

pending completion
5478073159

Pull #645

github

web-flow
Merge 856821622 into 9f6c5e5c5
Pull Request #645: ci: run tests on parallel

1574 of 1782 branches covered (88.33%)

Branch coverage included in aggregate %.

2435 of 2475 relevant lines covered (98.38%)

482.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.47
/packages/metascraper/src/rules.js
1
'use strict'
118✔
2

118✔
3
const {
118✔
4
  cloneDeep,
118✔
5
  concat,
118✔
6
  first,
118✔
7
  findIndex,
118✔
8
  forEach,
118✔
9
  chain,
118✔
10
  castArray,
118✔
11
  has,
118✔
12
  set
118✔
13
} = require('lodash')
118✔
14

118✔
15
const forEachRule = (collection, fn) => forEach(castArray(collection), fn)
118✔
16

118✔
17
const loadRules = rulesBundle =>
118✔
18
  chain(rulesBundle)
217✔
19
    .reduce((acc, { test, ...rules }) => {
217✔
20
      forEach(rules, (innerRules, propName) => {
1,802✔
21
        if (test) forEachRule(innerRules, rule => (rule.test = test))
2,834!
22

2,834✔
23
        set(
2,834✔
24
          acc,
2,834✔
25
          propName,
2,834✔
26
          has(acc, propName)
2,834✔
27
            ? concat(acc[propName], innerRules)
2,834✔
28
            : concat(innerRules)
2,834✔
29
        )
2,834✔
30

2,834✔
31
        return acc
2,834✔
32
      })
1,802✔
33
      return acc
1,802✔
34
    }, {})
217✔
35
    .toPairs()
217✔
36
    .value()
217✔
37

118✔
38
const mergeRules = (rules, baseRules) =>
118✔
39
  chain(rules)
250✔
40
    .reduce((acc, { test, ...rules }) => {
250✔
41
      forEach(rules, (innerRules, propName) => {
3✔
42
        if (test) forEachRule(innerRules, rule => (rule.test = test))
4!
43
        // find the rules associated with `propName`
4✔
44
        const index = findIndex(acc, item => first(item) === propName)
4✔
45
        // if `propName` has more rule, add the new rule from the end
4✔
46
        if (index !== -1) acc[index][1] = concat(innerRules, ...acc[index][1])
4✔
47
        // otherwise, create an array of rules
3✔
48
        else acc.push([propName, castArray(innerRules)])
3✔
49
      })
3✔
50
      return acc
3✔
51
    }, cloneDeep(baseRules))
250✔
52
    .value()
250✔
53

118✔
54
module.exports = { mergeRules, loadRules }
118✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc