Skip to content

Commit

Permalink
test: fix test failing due to content filters
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlj95 committed Oct 30, 2024
1 parent c6f4b86 commit 2b3a25f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ describe('Tree shakeable manager providers migration', () => {
let runner: SchematicTestRunner
let tree: UnitTestTree
let logWarnSpy: jest.Spied<(typeof logging.Logger.prototype)['warn']>
const [SAMPLE_OLD_IDENTIFIER, SAMPLE_NEW_IDENTIFIER, SAMPLE_ENTRYPOINT] = [
Object.keys(STANDARD_REPLACEMENTS.identifierReplacements)[0],
Object.values(STANDARD_REPLACEMENTS.identifierReplacements)[0],
'standard',
]
const SAMPLE_TYPESCRIPT_FILE_PATH = '/index.ts'

beforeEach(async () => {
Expand Down Expand Up @@ -180,22 +175,24 @@ describe('Tree shakeable manager providers migration', () => {
})

describe('when namespace imports are used to import the library', () => {
const [SAMPLE_OLD_IDENTIFIER, SAMPLE_NEW_IDENTIFIER, SAMPLE_ENTRYPOINT] = [
...STANDARD_REPLACEMENTS.sampleReplacement,
'standard',
]
const namespaceImport = `import ngxMetaMetadataModule from '${LIB_NAME}/${SAMPLE_ENTRYPOINT}'`
const oldUsage = `ngxMetaMetadataModule.${SAMPLE_OLD_IDENTIFIER}`
const newUsage = `ngxMetaMetadataModule.${SAMPLE_NEW_IDENTIFIER}()`
const fileWithOldUsage = `
${namespaceImport}
it('should leave the import as is', async () => {
tree.create(SAMPLE_TYPESCRIPT_FILE_PATH, namespaceImport)
const providers = [ngxMetaMetadataModule.${SAMPLE_OLD_IDENTIFIER}]
`
const fileWithNewUsage = `
${namespaceImport}
await runMigration()

expect(tree.readContent(SAMPLE_TYPESCRIPT_FILE_PATH)).toEqual(
namespaceImport,
)
})
const providers = [ngxMetaMetadataModule.${SAMPLE_NEW_IDENTIFIER}()]
`

it('should warn about it', async () => {
tree.create(SAMPLE_TYPESCRIPT_FILE_PATH, namespaceImport)
tree.create(SAMPLE_TYPESCRIPT_FILE_PATH, fileWithOldUsage)

await runMigration()

Expand All @@ -204,24 +201,13 @@ describe('Tree shakeable manager providers migration', () => {
)
})

it('should replace those usages too', async () => {
tree.create(
SAMPLE_TYPESCRIPT_FILE_PATH,
`${namespaceImport}
const providers = [
${oldUsage},
]`,
)
it('should replace those usages too, leaving import as is', async () => {
tree.create(SAMPLE_TYPESCRIPT_FILE_PATH, fileWithOldUsage)

await runMigration()

expect(tree.readContent(SAMPLE_TYPESCRIPT_FILE_PATH)).toEqual(
`${namespaceImport}
const providers = [
${newUsage},
]`,
fileWithNewUsage,
)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class ModuleReplacements {
.map((newIdentifier) => `${newIdentifier}()`)
.join(',\n')
}

get sampleReplacement() {
return Object.entries(this.identifierReplacements)[0]
}
}

export const JSON_LD_REPLACEMENTS: ModuleReplacements = new ModuleReplacements({
Expand Down

0 comments on commit 2b3a25f

Please sign in to comment.