Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fibble

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fibble - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

acceptancetest/bottom-module.js

18

acceptancetest/test.js
import { equal } from 'assert'
import { replace, reset } from '../lib/replace.js'
import { topValue } from './top-module.js'

@@ -7,2 +8,3 @@ await replace('pad', { default: (string) => `${string} padded` })

const { main: withStub } = await import('./file-under-test.js')
equal(

@@ -13,2 +15,18 @@ withStub,

)
equal(
topValue,
'bottom value processed by middle processed by top',
'Top module incorectly loaded',
)
await replace('./bottom-module.js', { bottomValue: 'fake bottom value' })
const { middleValue } = await import('./middle-module.js')
equal(
middleValue,
'fake bottom value processed by middle',
'Bottom module not replaced on second load',
)
reset()

@@ -15,0 +33,0 @@ // const { main: withoutStub } = await import('./file-under-test.js')

4

lib/emitting-state.js

@@ -9,6 +9,6 @@ import { FibbleState } from './state.js'

replace(fullPath, replacement) {
super.replace(fullPath, replacement)
replace(fullPath, replacement, parentURL) {
super.replace(fullPath, replacement, parentURL)
this.localPort.postMessage(this.getValues())
}
}

@@ -23,2 +23,5 @@ import { assert } from 'chai'

},
replacedFromCount: {
parentURL_A: 1,
},
})

@@ -82,17 +85,21 @@

it('returns count for default replacements', () => {
equal(info.getURLCount('withDefault'), 1)
equal(info.getURLCount('withDefault', 'unknownParent'), 1)
})
it('returns count for replacements with both default and keys', () => {
equal(info.getURLCount('withBoth'), 2)
equal(info.getURLCount('withBoth', 'unknownParent'), 2)
})
it('returns count for replacements with keys', () => {
equal(info.getURLCount('withKeys'), 3)
equal(info.getURLCount('withKeys', 'unknownParent'), 3)
})
it('returns count from parent urls', () => {
equal(info.getURLCount('unknown', 'parentURL_A'), 'parentURL_A-1')
})
it('returns undefined for unknown replacements', () => {
equal(info.getURLCount('unknown'), undefined)
equal(info.getURLCount('unknown', 'unknownParent'), undefined)
})
})
})

@@ -6,8 +6,15 @@ export class FibbleInfo {

this.replacementKeys = {}
this.replacedFromCount = {}
}
setValues({ defaultReplacements, counts, replacementKeys }) {
setValues({
defaultReplacements,
counts,
replacementKeys,
replacedFromCount,
}) {
this.defaultReplacements = defaultReplacements
this.counts = counts
this.replacementKeys = replacementKeys
this.replacedFromCount = replacedFromCount
}

@@ -20,2 +27,3 @@

replacementKeys: this.replacementKeys,
replacedFromCount: this.replacedFromCount,
}

@@ -39,5 +47,8 @@ }

getURLCount(fullPath) {
return this.counts[fullPath]
getURLCount(fullPath, parentURL) {
const pathCount = this.counts[fullPath]
if (pathCount != null) return pathCount
const parentCount = this.replacedFromCount[parentURL]
if (parentCount != null) return `${parentURL}-${parentCount}`
}
}

@@ -10,3 +10,3 @@ import { stateFactory } from './state-factory.js'

const fullPath = await import.meta.resolve(relPath, parentURL)
fibbleState.replace(cleanURL(fullPath), replacement)
fibbleState.replace(cleanURL(fullPath), replacement, parentURL)
}

@@ -13,0 +13,0 @@

@@ -14,3 +14,4 @@ import { replaceFileURL } from './utils.js'

const count = fibbleInfo.getURLCount(url)
const { parentURL } = context
const count = fibbleInfo.getURLCount(url, parentURL)
return count != null

@@ -17,0 +18,0 @@ ? shortCircuit(`${url}?__fibbleCount=${count}`)

@@ -17,6 +17,7 @@ import { assert } from 'chai'

const replacementWithDefault = { default: 'someDefault' }
const replacedFrom = 'someParentURL'
describe('set replacement', () => {
beforeEach(() => {
state.replace(path, replacement)
state.replace(pathWithDefault, replacementWithDefault)
state.replace(path, replacement, replacedFrom)
state.replace(pathWithDefault, replacementWithDefault, replacedFrom)
})

@@ -30,4 +31,4 @@

it('gives you a count of how many times it has been replaced', () => {
equal(state.getURLCount(path), 1)
isUndefined(state.getURLCount('someUnknownPath'))
equal(state.getURLCount(path, replacedFrom), 1)
isUndefined(state.getURLCount('someUnknownPath', 'someUnknownParent'))
})

@@ -60,2 +61,9 @@

})
it('returns a count for paths resolved from the parent url', () => {
equal(
state.getURLCount('someUnknownPath', replacedFrom),
'someParentURL-2',
)
})
})

@@ -65,4 +73,4 @@

beforeEach(() => {
state.replace(path, replacement)
state.replace(pathWithDefault, replacementWithDefault)
state.replace(path, replacement, replacedFrom)
state.replace(pathWithDefault, replacementWithDefault, replacedFrom)
state.reset(path, replacement)

@@ -85,9 +93,9 @@ })

it('increases the count for all repaced items', () => {
equal(state.getURLCount(path), 2)
equal(state.getURLCount(path, replacedFrom), 2)
})
it('does not affect count for non replaced items', () => {
isUndefined(state.getURLCount('someUnknownPath'))
isUndefined(state.getURLCount('someUnknownPath', 'someUnknownParent'))
})
})
})

@@ -9,8 +9,10 @@ import { FibbleInfo } from './info.js'

replace(fullPath, replacement) {
replace(fullPath, replacement, parentURL) {
const allReplacementKeys = Object.keys(replacement)
const replacementKeys = allReplacementKeys.filter((k) => k !== 'default')
const currentCount = this.counts[fullPath] || 0
const currentReplacedFromCount = this.replacedFromCount[parentURL] || 0
this.counts[fullPath] = currentCount + 1
this.replacedFromCount[parentURL] = currentReplacedFromCount + 1
this.replacements[fullPath] = replacement

@@ -17,0 +19,0 @@ this.replacementKeys[fullPath] = replacementKeys

{
"name": "fibble",
"version": "1.2.1",
"version": "1.2.2",
"description": "Small library to insert test doubles into your tests",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc