-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added files from addon-test-support to addon.publicEntrypoints() (#11)
* refactor: Renamed changeDirectory to renameDirectory. Updated its API. * chore: Simplified tests for mapFilePaths. Added failing tests. * bugfix: Updated renameDirectory to provide a new path only when there is a match * refactor: Used renameDirectory to better separate concerns from the glob package * feature: Added the files from test-support to publicEntrypoints * refactor: Added tests for blueprints and test-support Co-authored-by: ijlee2 <[email protected]>
- Loading branch information
Showing
6 changed files
with
218 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
function changeDirectory(oldPath, from, to) { | ||
if (!oldPath.startsWith(from)) { | ||
throw new RangeError( | ||
`The provided path \`${oldPath}\` does not start with \`${from}\`.` | ||
); | ||
import { join } from 'node:path'; | ||
|
||
export function renameDirectory(oldPath, { from, to }) { | ||
if (from === '') { | ||
return join(to, oldPath); | ||
} | ||
|
||
const relativePath = oldPath.replace(new RegExp(`^${from}/`), ''); | ||
const newPath = `${to}/${relativePath}`; | ||
if (!oldPath.startsWith(`${from}/`)) { | ||
return oldPath; | ||
} | ||
|
||
return [oldPath, newPath]; | ||
return join(to, oldPath.replace(`${from}/`, '')); | ||
} | ||
|
||
export function mapFilePaths(filePaths, directory) { | ||
const { from, to } = directory; | ||
|
||
return new Map( | ||
filePaths.map((filePath) => changeDirectory(filePath, from, to)) | ||
filePaths.map((filePath) => { | ||
const newPath = renameDirectory(filePath, { from, to }); | ||
|
||
return [filePath, newPath]; | ||
}) | ||
); | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/migration/ember-addon/steps/analyze-addon/blueprints-and-test-support.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { analyzeAddon } from '../../../../../src/migration/ember-addon/steps/index.js'; | ||
import { | ||
codemodOptions, | ||
options, | ||
} from '../../../../helpers/shared-test-setups/typescript.js'; | ||
import { assert, loadFixture, test } from '../../../../helpers/testing.js'; | ||
|
||
test('migration | ember-addon | steps | analyze-addon > blueprints and test-support', function () { | ||
const inputProject = { | ||
'addon-test-support': { | ||
components: { | ||
'container-query.ts': '', | ||
}, | ||
'index.ts': `export * from './components/container-query';\n`, | ||
}, | ||
blueprints: { | ||
'ember-container-query': { | ||
files: { | ||
'some-folder': { | ||
'some-file.ts': '', | ||
}, | ||
}, | ||
'index.ts': [ | ||
`module.exports = {`, | ||
` normalizeEntityName() {},`, | ||
`};`, | ||
``, | ||
].join('\n'), | ||
}, | ||
}, | ||
}; | ||
|
||
loadFixture(inputProject, codemodOptions); | ||
|
||
assert.deepEqual(analyzeAddon(options), { | ||
addon: { | ||
appReexports: [], | ||
publicEntrypoints: [ | ||
'test-support/components/container-query.js', | ||
'test-support/index.js', | ||
], | ||
}, | ||
projectRoot: { | ||
devDependencies: { | ||
concurrently: '^7.6.0', | ||
prettier: '^2.8.1', | ||
}, | ||
}, | ||
}); | ||
}); |
70 changes: 70 additions & 0 deletions
70
tests/migration/ember-addon/steps/move-addon-files/blueprints-and-test-support.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { moveAddonFiles } from '../../../../../src/migration/ember-addon/steps/index.js'; | ||
import { | ||
codemodOptions, | ||
options, | ||
} from '../../../../helpers/shared-test-setups/typescript.js'; | ||
import { | ||
assertFixture, | ||
loadFixture, | ||
test, | ||
} from '../../../../helpers/testing.js'; | ||
|
||
test('migration | ember-addon | steps | move-addon-files > blueprints and test-support', function () { | ||
const inputProject = { | ||
'addon-test-support': { | ||
components: { | ||
'container-query.ts': '', | ||
}, | ||
'index.ts': `export * from './components/container-query';\n`, | ||
}, | ||
blueprints: { | ||
'ember-container-query': { | ||
files: { | ||
'some-folder': { | ||
'some-file.ts': '', | ||
}, | ||
}, | ||
'index.ts': [ | ||
`module.exports = {`, | ||
` normalizeEntityName() {},`, | ||
`};`, | ||
``, | ||
].join('\n'), | ||
}, | ||
}, | ||
}; | ||
|
||
const outputProject = { | ||
'ember-container-query': { | ||
blueprints: { | ||
'ember-container-query': { | ||
files: { | ||
'some-folder': { | ||
'some-file.ts': '', | ||
}, | ||
}, | ||
'index.ts': [ | ||
`module.exports = {`, | ||
` normalizeEntityName() {},`, | ||
`};`, | ||
``, | ||
].join('\n'), | ||
}, | ||
}, | ||
src: { | ||
'test-support': { | ||
components: { | ||
'container-query.ts': '', | ||
}, | ||
'index.ts': `export * from './components/container-query';\n`, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
loadFixture(inputProject, codemodOptions); | ||
|
||
moveAddonFiles(options); | ||
|
||
assertFixture(outputProject, codemodOptions); | ||
}); |
40 changes: 0 additions & 40 deletions
40
tests/migration/ember-addon/steps/move-addon-files/other-files.test.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters