Skip to content

Commit

Permalink
feat: add flag moveAllToComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed Apr 6, 2024
1 parent bad0e32 commit 93877bc
Show file tree
Hide file tree
Showing 2 changed files with 529 additions and 33 deletions.
214 changes: 207 additions & 7 deletions test/Optimizer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { inputJSON, inputYAML, outputJSON, outputYAML } from './fixtures'
import {
inputJSON,
inputYAML,
outputJSON_mATCFalse_mDTCTrue_schemaFalse,
outputYAML_mATCFalse_mDTCTrue_schemaFalse,
outputYAML_mATCTrue_mDTCFalse_schemaFalse,
outputJSON_mATCTrue_mDTCFalse_schemaFalse,
outputYAML_mATCFalse_mDTCTrue_schemaTrue,
outputJSON_mATCFalse_mDTCTrue_schemaTrue,
outputYAML_mATCTrue_mDTCFalse_schemaTrue,
outputJSON_mATCTrue_mDTCFalse_schemaTrue,
} from './fixtures'
import { Optimizer } from '../src'
import { Output } from '../src/Optimizer'

describe('Optimizer', () => {
it('should produce the correct optimized file with YAML input.', async () => {
it('should produce the correct optimized file with YAML input and `{ moveAllToComponents: false, moveDuplicatesToComponents: true }, disableOptimizationFor: { schema: false } }`.', async () => {
const optimizer = new Optimizer(inputYAML)
await optimizer.getReport()
expect(
Expand All @@ -21,10 +32,10 @@ describe('Optimizer', () => {
},
})
.trim()
).toEqual(outputYAML.trim())
).toEqual(outputYAML_mATCFalse_mDTCTrue_schemaFalse.trim())
})

it('should produce the correct optimized file with JSON input.', async () => {
it('should produce the correct optimized file with JSON input and `{ moveAllToComponents: false, moveDuplicatesToComponents: true }, disableOptimizationFor: { schema: false } }`.', async () => {
const optimizer = new Optimizer(inputJSON)
await optimizer.getReport()
expect(
Expand All @@ -42,10 +53,10 @@ describe('Optimizer', () => {
},
})
.trim()
).toEqual(outputYAML.trim())
).toEqual(outputYAML_mATCFalse_mDTCTrue_schemaFalse.trim())
})

it('should produce the correct JSON output.', async () => {
it('should produce the correct JSON output and `{ moveAllToComponents: false, moveDuplicatesToComponents: true }, disableOptimizationFor: { schema: false } }`.', async () => {
const optimizer = new Optimizer(inputYAML)
await optimizer.getReport()
expect(
Expand All @@ -63,6 +74,195 @@ describe('Optimizer', () => {
},
})
.trim()
).toEqual(outputJSON.trim())
).toEqual(outputJSON_mATCFalse_mDTCTrue_schemaFalse.trim())
})

it('should produce the correct optimized file with YAML input and `{ moveAllToComponents: true, moveDuplicatesToComponents: false }, disableOptimizationFor: { schema: false } }`.', async () => {
const optimizer = new Optimizer(inputYAML)
await optimizer.getReport()
expect(
optimizer
.getOptimizedDocument({
output: Output.YAML,
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: true,
moveDuplicatesToComponents: false,
},
disableOptimizationFor: {
schema: false,
},
})
.trim()
).toEqual(outputYAML_mATCTrue_mDTCFalse_schemaFalse.trim())
})

it('should produce the correct optimized file with JSON input and `{ moveAllToComponents: true, moveDuplicatesToComponents: false }, disableOptimizationFor: { schema: false } }`.', async () => {
const optimizer = new Optimizer(inputJSON)
await optimizer.getReport()
expect(
optimizer
.getOptimizedDocument({
output: Output.YAML,
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: true,
moveDuplicatesToComponents: false,
},
disableOptimizationFor: {
schema: false,
},
})
.trim()
).toEqual(outputYAML_mATCTrue_mDTCFalse_schemaFalse.trim())
})

it('should produce the correct JSON output and `{ moveAllToComponents: true, moveDuplicatesToComponents: false }, disableOptimizationFor: { schema: false } }`.', async () => {
const optimizer = new Optimizer(inputYAML)
await optimizer.getReport()
expect(
optimizer
.getOptimizedDocument({
output: Output.JSON,
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: true,
moveDuplicatesToComponents: false,
},
disableOptimizationFor: {
schema: false,
},
})
.trim()
).toEqual(outputJSON_mATCTrue_mDTCFalse_schemaFalse.trim())
})

it('should produce the correct optimized file with YAML input and `{ moveAllToComponents: false, moveDuplicatesToComponents: true }, disableOptimizationFor: { schema: true } }`.', async () => {
const optimizer = new Optimizer(inputYAML)
await optimizer.getReport()
expect(
optimizer
.getOptimizedDocument({
output: Output.YAML,
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: false,
moveDuplicatesToComponents: true,
},
disableOptimizationFor: {
schema: true,
},
})
.trim()
).toEqual(outputYAML_mATCFalse_mDTCTrue_schemaTrue.trim())
})

it('should produce the correct optimized file with JSON input and `{ moveAllToComponents: false, moveDuplicatesToComponents: true }, disableOptimizationFor: { schema: true } }`.', async () => {
const optimizer = new Optimizer(inputJSON)
await optimizer.getReport()
expect(
optimizer
.getOptimizedDocument({
output: Output.YAML,
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: false,
moveDuplicatesToComponents: true,
},
disableOptimizationFor: {
schema: true,
},
})
.trim()
).toEqual(outputYAML_mATCFalse_mDTCTrue_schemaTrue.trim())
})

it('should produce the correct JSON output and `{ moveAllToComponents: false, moveDuplicatesToComponents: true }, disableOptimizationFor: { schema: true } }`.', async () => {
const optimizer = new Optimizer(inputYAML)
await optimizer.getReport()
expect(
optimizer
.getOptimizedDocument({
output: Output.JSON,
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: false,
moveDuplicatesToComponents: true,
},
disableOptimizationFor: {
schema: true,
},
})
.trim()
).toEqual(outputJSON_mATCFalse_mDTCTrue_schemaTrue.trim())
})

it('should produce the correct optimized file with YAML input and `{ moveAllToComponents: true, moveDuplicatesToComponents: false }, disableOptimizationFor: { schema: true } }`.', async () => {
const optimizer = new Optimizer(inputYAML)
await optimizer.getReport()
expect(
optimizer
.getOptimizedDocument({
output: Output.YAML,
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: true,
moveDuplicatesToComponents: false,
},
disableOptimizationFor: {
schema: true,
},
})
.trim()
).toEqual(outputYAML_mATCTrue_mDTCFalse_schemaTrue.trim())
})

it('should produce the correct optimized file with JSON input and `{ moveAllToComponents: true, moveDuplicatesToComponents: false }, disableOptimizationFor: { schema: true } }`.', async () => {
const optimizer = new Optimizer(inputJSON)
await optimizer.getReport()
expect(
optimizer
.getOptimizedDocument({
output: Output.YAML,
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: true,
moveDuplicatesToComponents: false,
},
disableOptimizationFor: {
schema: true,
},
})
.trim()
).toEqual(outputYAML_mATCTrue_mDTCFalse_schemaTrue.trim())
})

it('should produce the correct JSON output and `{ moveAllToComponents: true, moveDuplicatesToComponents: false }, disableOptimizationFor: { schema: true } }`.', async () => {
const optimizer = new Optimizer(inputYAML)
await optimizer.getReport()
expect(
optimizer
.getOptimizedDocument({
output: Output.JSON,
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: true,
moveDuplicatesToComponents: false,
},
disableOptimizationFor: {
schema: true,
},
})
.trim()
).toEqual(outputJSON_mATCTrue_mDTCFalse_schemaTrue.trim())
})
})
Loading

0 comments on commit 93877bc

Please sign in to comment.