Skip to content

Commit

Permalink
fix: empty inFile metadata detection (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon authored Aug 30, 2023
1 parent ca6d5a7 commit 66ef9d9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 78 deletions.
17 changes: 11 additions & 6 deletions __tests__/unit/lib/utils/metadataDiff.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,20 @@ describe(`MetadataDiff`, () => {
await metadataDiff.compare('file/path')

// Act
metadataDiff.prune()
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith(alertOther)
expect(isEmpty).toBe(false)
})
it('given zero element added and one element delete, the generated file contains empty declaration', async () => {
it('given every element deleted, the generated file is empty', async () => {
// Arrange
parseXmlFileToJson.mockResolvedValueOnce(alertTest)
parseXmlFileToJson.mockResolvedValueOnce(alert)
await metadataDiff.compare('file/path')

// Act
metadataDiff.prune()
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith({
Expand All @@ -239,6 +240,7 @@ describe(`MetadataDiff`, () => {
alerts: [],
},
})
expect(isEmpty).toBe(true)
})
it('given file contains only new element, it keeps the file identical', async () => {
// Arrange
Expand All @@ -247,10 +249,11 @@ describe(`MetadataDiff`, () => {
await metadataDiff.compare('file/path')

// Act
metadataDiff.prune()
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith(alert)
expect(isEmpty).toBe(false)
})

it('given one element modified, the generated file contains only this element', async () => {
Expand All @@ -266,10 +269,11 @@ describe(`MetadataDiff`, () => {
await metadataDiff.compare('file/path')

// Act
metadataDiff.prune()
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith(alertOther)
expect(isEmpty).toBe(false)
})

it('given untracked element, nothing trackable changed, the generated file contains untracked elements', async () => {
Expand All @@ -279,10 +283,11 @@ describe(`MetadataDiff`, () => {
await metadataDiff.compare('file/path')

// Act
metadataDiff.prune()
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith(unTracked)
expect(isEmpty).toBe(false)
})
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@salesforce/ts-sinon": "^1.4.15",
"@stryker-mutator/core": "^7.1.1",
"@stryker-mutator/jest-runner": "^7.1.1",
"@swc/core": "^1.3.80",
"@swc/core": "^1.3.81",
"@types/mocha": "^10.0.1",
"@types/node": "^20.5.7",
"@typescript-eslint/parser": "^6.5.0",
Expand Down
7 changes: 1 addition & 6 deletions src/utils/metadataDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ const extractMetadataForSubtype = fileContent => subType =>
const isEmpty = fileContent =>
Object.entries(getRootMetadata(fileContent))
.filter(([key]) => !key.startsWith(ATTRIBUTE_PREFIX))
.every(
value =>
value === null ||
value === undefined ||
(Array.isArray(value) && value.length === 0)
)
.every(([, value]) => Array.isArray(value) && value.length === 0)

// Diff processing functional area
const compareContent = attributes => (contentAtRef, otherContent, predicat) =>
Expand Down
130 changes: 65 additions & 65 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -870,13 +870,13 @@ __metadata:
linkType: hard

"@humanwhocodes/config-array@npm:^0.11.10":
version: 0.11.10
resolution: "@humanwhocodes/config-array@npm:0.11.10"
version: 0.11.11
resolution: "@humanwhocodes/config-array@npm:0.11.11"
dependencies:
"@humanwhocodes/object-schema": ^1.2.1
debug: ^4.1.1
minimatch: ^3.0.5
checksum: 1b1302e2403d0e35bc43e66d67a2b36b0ad1119efc704b5faff68c41f791a052355b010fb2d27ef022670f550de24cd6d08d5ecf0821c16326b7dcd0ee5d5d8a
checksum: db84507375ab77b8ffdd24f498a5b49ad6b64391d30dd2ac56885501d03964d29637e05b1ed5aefa09d57ac667e28028bc22d2da872bfcd619652fbdb5f4ca19
languageName: node
linkType: hard

Expand Down Expand Up @@ -1348,8 +1348,8 @@ __metadata:
linkType: hard

"@oclif/core@npm:^2.11.10":
version: 2.12.0
resolution: "@oclif/core@npm:2.12.0"
version: 2.13.0
resolution: "@oclif/core@npm:2.13.0"
dependencies:
"@types/cli-progress": ^3.11.0
ansi-escapes: ^4.3.2
Expand Down Expand Up @@ -1381,7 +1381,7 @@ __metadata:
widest-line: ^3.1.0
wordwrap: ^1.0.0
wrap-ansi: ^7.0.0
checksum: 6e50d5711a4103aa3410e9e869525633cbe05aa5edf2d8eb24e989bf824b47150613e479abcd1f35454612be17a949ae979fb7ac017098baa825bf2986dc37af
checksum: 5f7381a3bf7f31b691c61d275fefc5e66c246626a6e3df4bc4a0cfe5bedf65778092c194a1b4148094ee3020f6da514cda76bb0803b422c419098074ec977e87
languageName: node
linkType: hard

Expand Down Expand Up @@ -1920,91 +1920,91 @@ __metadata:
languageName: node
linkType: hard

"@swc/core-darwin-arm64@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-darwin-arm64@npm:1.3.80"
"@swc/core-darwin-arm64@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-darwin-arm64@npm:1.3.81"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard

"@swc/core-darwin-x64@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-darwin-x64@npm:1.3.80"
"@swc/core-darwin-x64@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-darwin-x64@npm:1.3.81"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard

"@swc/core-linux-arm-gnueabihf@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-linux-arm-gnueabihf@npm:1.3.80"
"@swc/core-linux-arm-gnueabihf@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-linux-arm-gnueabihf@npm:1.3.81"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard

"@swc/core-linux-arm64-gnu@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-linux-arm64-gnu@npm:1.3.80"
"@swc/core-linux-arm64-gnu@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-linux-arm64-gnu@npm:1.3.81"
conditions: os=linux & cpu=arm64 & libc=glibc
languageName: node
linkType: hard

"@swc/core-linux-arm64-musl@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-linux-arm64-musl@npm:1.3.80"
"@swc/core-linux-arm64-musl@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-linux-arm64-musl@npm:1.3.81"
conditions: os=linux & cpu=arm64 & libc=musl
languageName: node
linkType: hard

"@swc/core-linux-x64-gnu@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-linux-x64-gnu@npm:1.3.80"
"@swc/core-linux-x64-gnu@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-linux-x64-gnu@npm:1.3.81"
conditions: os=linux & cpu=x64 & libc=glibc
languageName: node
linkType: hard

"@swc/core-linux-x64-musl@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-linux-x64-musl@npm:1.3.80"
"@swc/core-linux-x64-musl@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-linux-x64-musl@npm:1.3.81"
conditions: os=linux & cpu=x64 & libc=musl
languageName: node
linkType: hard

"@swc/core-win32-arm64-msvc@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-win32-arm64-msvc@npm:1.3.80"
"@swc/core-win32-arm64-msvc@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-win32-arm64-msvc@npm:1.3.81"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard

"@swc/core-win32-ia32-msvc@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-win32-ia32-msvc@npm:1.3.80"
"@swc/core-win32-ia32-msvc@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-win32-ia32-msvc@npm:1.3.81"
conditions: os=win32 & cpu=ia32
languageName: node
linkType: hard

"@swc/core-win32-x64-msvc@npm:1.3.80":
version: 1.3.80
resolution: "@swc/core-win32-x64-msvc@npm:1.3.80"
"@swc/core-win32-x64-msvc@npm:1.3.81":
version: 1.3.81
resolution: "@swc/core-win32-x64-msvc@npm:1.3.81"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard

"@swc/core@npm:^1.3.80":
version: 1.3.80
resolution: "@swc/core@npm:1.3.80"
"@swc/core@npm:^1.3.81":
version: 1.3.81
resolution: "@swc/core@npm:1.3.81"
dependencies:
"@swc/core-darwin-arm64": 1.3.80
"@swc/core-darwin-x64": 1.3.80
"@swc/core-linux-arm-gnueabihf": 1.3.80
"@swc/core-linux-arm64-gnu": 1.3.80
"@swc/core-linux-arm64-musl": 1.3.80
"@swc/core-linux-x64-gnu": 1.3.80
"@swc/core-linux-x64-musl": 1.3.80
"@swc/core-win32-arm64-msvc": 1.3.80
"@swc/core-win32-ia32-msvc": 1.3.80
"@swc/core-win32-x64-msvc": 1.3.80
"@swc/types": ^0.1.3
"@swc/core-darwin-arm64": 1.3.81
"@swc/core-darwin-x64": 1.3.81
"@swc/core-linux-arm-gnueabihf": 1.3.81
"@swc/core-linux-arm64-gnu": 1.3.81
"@swc/core-linux-arm64-musl": 1.3.81
"@swc/core-linux-x64-gnu": 1.3.81
"@swc/core-linux-x64-musl": 1.3.81
"@swc/core-win32-arm64-msvc": 1.3.81
"@swc/core-win32-ia32-msvc": 1.3.81
"@swc/core-win32-x64-msvc": 1.3.81
"@swc/types": ^0.1.4
peerDependencies:
"@swc/helpers": ^0.5.0
dependenciesMeta:
Expand All @@ -2031,11 +2031,11 @@ __metadata:
peerDependenciesMeta:
"@swc/helpers":
optional: true
checksum: c23af8e43fe001fd211a36954372877515267ab4d019e63896160adc76d9271ce0301d9610d0220ccc4bf8c97c757fffa83d9ef358d5f1810d2ee4482eb3d2a9
checksum: 2d1f97294ab923dc15b0596ea792659cef72e6a35addf4d978cd1d6d99f2dc2ae3a86ffd0e31a9ba98c58e5260a819368587018658fa423a0d64cd2599c28d45
languageName: node
linkType: hard

"@swc/types@npm:^0.1.3":
"@swc/types@npm:^0.1.4":
version: 0.1.4
resolution: "@swc/types@npm:0.1.4"
checksum: 9b09de7dca8e4b19bfb43f9e332c771855158cb761d26000807fe858447ecbc5342a6c257b26d9aa5497f7138fc58913693e2bee222e5042e0e8f57c2979ae66
Expand Down Expand Up @@ -4286,9 +4286,9 @@ __metadata:
linkType: hard

"electron-to-chromium@npm:^1.4.477":
version: 1.4.504
resolution: "electron-to-chromium@npm:1.4.504"
checksum: 537860f9f99e53cf9b9f98ad9831094b9473beee512ff5a12c20cc89fa2fb64f90d903ab878fac0e20f6c041f9324d3cbda9bea71870dd97d4ecc2f8da6388fa
version: 1.4.505
resolution: "electron-to-chromium@npm:1.4.505"
checksum: e3255e2d136c88370548d3eb086924f49085438ff4268a47b005b96bd024ccd2da9b4d2887d8999920b67f3693490faaae0ca204ca593785e6070a560a66f3cc
languageName: node
linkType: hard

Expand Down Expand Up @@ -6142,15 +6142,15 @@ __metadata:
linkType: hard

"jackspeak@npm:^2.0.3":
version: 2.3.0
resolution: "jackspeak@npm:2.3.0"
version: 2.3.1
resolution: "jackspeak@npm:2.3.1"
dependencies:
"@isaacs/cliui": ^8.0.2
"@pkgjs/parseargs": ^0.11.0
dependenciesMeta:
"@pkgjs/parseargs":
optional: true
checksum: 71bf716f4b5793226d4aeb9761ebf2605ee093b59f91a61451d57d998dd64bbf2b54323fb749b8b2ae8b6d8a463de4f6e3fedab50108671f247bbc80195a6306
checksum: 34ea4d618d8d36ac104fe1053c85dfb6a63306cfe87e157ef42f18a7aa30027887370a4e163dd4993e45c6bf8a8ae003bf8476fdb8538e8ee5cd1938c27b15d0
languageName: node
linkType: hard

Expand Down Expand Up @@ -8498,13 +8498,13 @@ __metadata:
linkType: hard

"postcss@npm:^8.1.10":
version: 8.4.28
resolution: "postcss@npm:8.4.28"
version: 8.4.29
resolution: "postcss@npm:8.4.29"
dependencies:
nanoid: ^3.3.6
picocolors: ^1.0.0
source-map-js: ^1.0.2
checksum: f605c24a36f7e400bad379735fbfc893ccb8d293ad6d419bb824db77cdcb69f43d614ef35f9f7091f32ca588d130ec60dbcf53b366e6bf88a8a64bbeb3c05f6d
checksum: dd6daa25e781db9ae5b651d9b7bfde0ec6e60e86a37da69a18eb4773d5ddd51e28fc4ff054fbdc04636a31462e6bf09a1e50986f69ac52b10d46b7457cd36d12
languageName: node
linkType: hard

Expand Down Expand Up @@ -9262,7 +9262,7 @@ __metadata:
"@salesforce/ts-sinon": ^1.4.15
"@stryker-mutator/core": ^7.1.1
"@stryker-mutator/jest-runner": ^7.1.1
"@swc/core": ^1.3.80
"@swc/core": ^1.3.81
"@types/mocha": ^10.0.1
"@types/node": ^20.5.7
"@typescript-eslint/parser": ^6.5.0
Expand Down Expand Up @@ -10061,9 +10061,9 @@ __metadata:
linkType: hard

"ts-retry-promise@npm:^0.7.0":
version: 0.7.0
resolution: "ts-retry-promise@npm:0.7.0"
checksum: 66adbdffd994868ad3ffc148cf2143f8bc002f5e4de3b6d4dc58b6b605b6995c4f06133a17896cc472e688bfe274d7e1fa78c1c86d35147a2b6694d9f61cccec
version: 0.7.1
resolution: "ts-retry-promise@npm:0.7.1"
checksum: ff88b7687336dbb972c357bd5ee5ce4c06d8e55964e512cfbca4979108b2b2bb91369157472e6dd9f39592c994c8d592670760b3e223bc9adc36c6103235d9aa
languageName: node
linkType: hard

Expand Down

0 comments on commit 66ef9d9

Please sign in to comment.