Skip to content

Commit

Permalink
fix(test): fix extension handling
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed Jun 13, 2024
1 parent 7674e03 commit 63c749a
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion configuration/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ module.exports = babel`
contents = `module.exports = ${JSON.stringify(configuration, null, 2)}`
}

return { name: `babel.config.${state.extension}`, contents }
return { name: `babel.config.${state.extension === 'json' ? 'js' : state.extension}`, contents }
}
2 changes: 1 addition & 1 deletion configuration/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default cypress`
contents = `export default ${JSON.stringify(configuration, null, 2)}`
}

return { name: `cypress.config.${state.extension}`, contents }
return { name: `cypress.config.${state.extension === 'json' ? 'js' : state.extension}`, contents }
}
2 changes: 1 addition & 1 deletion configuration/metro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ module.exports = mergeConfig(getDefaultConfig(__dirname), metro)`
module.exports = mergeConfig(getDefaultConfig(__dirname), ${JSON.stringify(configuration, null, 2)})`
}

return { name: 'metro.config.cjs', contents }
return { name: `metro.config.${state.extension === 'json' ? 'js' : state.extension}`, contents }
}
2 changes: 1 addition & 1 deletion configuration/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default playwright`
contents = `export default ${JSON.stringify(configuration, null, 2)}`
}

return { name: `playwright.config.${state.extension}`, contents }
return { name: `playwright.config.${state.extension === 'json' ? 'js' : state.extension}`, contents }
}
2 changes: 1 addition & 1 deletion configuration/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export default postcss`
contents = `export default ${JSON.stringify(configuration, null, 2)}`
}

return { name: `postcss.config.${state.extension}`, contents }
return { name: `postcss.config.${state.extension === 'json' ? 'js' : state.extension}`, contents }
}
6 changes: 5 additions & 1 deletion configuration/prettier.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { state } from '../state'
import type { Template } from '../types'

/** @type {import("prettier").Config} */
Expand All @@ -19,7 +20,10 @@ export function createFile(configuration: Record<string, any>) {

const files = [
// TODO use prettier to format the whole file.
{ name: 'prettier.config.js', contents: `export default ${JSON.stringify(configuration, null, 2)}` },
{
name: `prettier.config.${state.extension === 'json' ? 'js' : state.extension}`,
contents: `export default ${JSON.stringify(configuration, null, 2)}`,
},
]

if (Array.isArray(ignores) && ignores.length) {
Expand Down
2 changes: 1 addition & 1 deletion configuration/rsbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export default extendConfiguration('rsbuild', rsbuild)`
contents = `export default ${JSON.stringify(configuration, null, 2)}`
}

return { name: `rsbuild.config.${state.extension}`, contents }
return { name: `rsbuild.config.${state.extension === 'json' ? 'js' : state.extension}`, contents }
}
2 changes: 1 addition & 1 deletion configuration/tailwind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default tailwind`
contents = `export default ${JSON.stringify(configuration, null, 2)}`
}

return { name: `tailwind.config.${state.extension}`, contents }
return { name: `tailwind.config.${state.extension === 'json' ? 'js' : state.extension}`, contents }
}
2 changes: 1 addition & 1 deletion configuration/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default vite`
contents = `export default ${JSON.stringify(configuration, null, 2)}`
}

return { name: `vite.config.${state.extension}`, contents }
return { name: `vite.config.${state.extension === 'json' ? 'ts' : state.extension}`, contents }
}
2 changes: 1 addition & 1 deletion configuration/vitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default vitest`
contents = `export default ${JSON.stringify(configuration, null, 2)}`
}

return { name: `vitest.config.${state.extension}`, contents }
return { name: `vitest.config.${state.extension === 'json' ? 'js' : state.extension}`, contents }
}
4 changes: 2 additions & 2 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test('Also parses JavaScript configuration.', async () => {

expect(existsSync(join(fixturePath, '.gitignore'))).toBe(true)
expect(await Bun.file(join(fixturePath, '.gitignore')).text()).toContain('please-ignore.js')
expect(existsSync(join(fixturePath, 'babel.config.cjs'))).toBe(true)
expect(existsSync(join(fixturePath, 'babel.config.js'))).toBe(true)
})

test('Extends existing configurations.', async () => {
Expand Down Expand Up @@ -120,7 +120,7 @@ test('Creates configuration files for various build-tool configurations.', () =>
// Not serializable in this case.
expect(existsSync(join(fixturePath, 'next.config.js'))).toBe(false)
// JavaScript only, but defined in package.json.
expect(existsSync(join(fixturePath, 'postcss.config.js'))).toBe(true)
expect(existsSync(join(fixturePath, 'postcss.config.ts'))).toBe(true)
})

test('Creates configuration files in all workspaces including the root.', async () => {
Expand Down

0 comments on commit 63c749a

Please sign in to comment.