Skip to content

Commit 97705e2

Browse files
Hristo HristovHristo Hristov
authored andcommitted
fix: add tests
1 parent 8d249f9 commit 97705e2

File tree

2 files changed

+99
-45
lines changed

2 files changed

+99
-45
lines changed

packages/core/update/Update.ts

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
122122
}
123123
updatePackageJsonFiles(pkgJsonFiles, upgradeable, fs);
124124
createNpmrc(rootPath, fs);
125-
updateGithubWorkflows(fs);
126-
updateAzureWorkflows(fs);
125+
updateWorkflows(fs);
127126

128127
return true;
129128
}
@@ -213,53 +212,51 @@ function updatePackageJsonFiles(
213212
}
214213
}
215214

216-
function updateWorkflows(
217-
fs: IFileSystem,
218-
basePath: string,
219-
workflowFiles: string[],
220-
oldInstallCmd: string,
221-
newInstallCmd: string
222-
): void {
223-
for (const fileName of workflowFiles) {
224-
const workflowPath = `${basePath}/${fileName}`;
225-
if (fs.fileExists(workflowPath)) {
226-
let workflow = fs.readFile(workflowPath);
227-
if (workflow) {
228-
workflow = workflow.replace(oldInstallCmd, newInstallCmd);
229-
fs.writeFile(workflowPath, workflow);
230-
}
231-
}
232-
}
233-
}
215+
function updateWorkflows(fs: IFileSystem): void {
216+
type WorkflowGroup = {
217+
basePath: string;
218+
files: string[];
219+
oldCmd: string;
220+
newCmd: string;
221+
};
234222

235-
function updateGithubWorkflows(fs: IFileSystem): void {
236-
updateWorkflows(
237-
fs,
238-
".github/workflows",
239-
["node.js.yml", "github-pages.yml"],
240-
"- run: npm i # replace with 'npm ci' after committing lock file from first install",
241-
`- run: echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
223+
const workflowGroups: WorkflowGroup[] = [
224+
{
225+
basePath: ".github/workflows",
226+
files: ["node.js.yml", "github-pages.yml"],
227+
oldCmd: "- run: npm i # replace with 'npm ci' after committing lock file from first install",
228+
newCmd: `- run: echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
242229
- run: echo "//packages.infragistics.com/npm/js-licensed/:_auth=\${{ secrets.NPM_AUTH_TOKEN }}" >> ~/.npmrc
243230
- run: echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
244231
- run: npm i # replace with 'npm ci' after committing lock file from first install`
245-
);
246-
}
247-
248-
function updateAzureWorkflows(fs: IFileSystem): void {
249-
updateWorkflows(
250-
fs,
251-
".azure/workflows",
252-
["azure-pipelines.yml"],
253-
"- script: npm i # replace with 'npm ci' after committing lock file from first install",
254-
`- script: |
255-
echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
256-
echo "//packages.infragistics.com/npm/js-licensed/:_auth=$NPM_AUTH_TOKEN" >> ~/.npmrc
257-
echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
258-
displayName: 'Authenticate'
259-
env:
260-
NPM_AUTH_TOKEN: $(NPM_AUTH_TOKEN)
232+
},
233+
{
234+
basePath: ".azure/workflows",
235+
files: ["azure-pipelines.yml"],
236+
oldCmd: "- script: npm i # replace with 'npm ci' after committing lock file from first install",
237+
newCmd: `- script: |
238+
echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
239+
echo "//packages.infragistics.com/npm/js-licensed/:_auth=$NPM_AUTH_TOKEN" >> ~/.npmrc
240+
echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
241+
displayName: 'Authenticate'
242+
env:
243+
NPM_AUTH_TOKEN: $(NPM_AUTH_TOKEN)
261244
- script: npm i # replace with 'npm ci' after committing lock file from first install`
262-
);
245+
}
246+
];
247+
248+
for (const group of workflowGroups) {
249+
for (const file of group.files) {
250+
const path = `${group.basePath}/${file}`;
251+
if (fs.fileExists(path)) {
252+
let content = fs.readFile(path);
253+
if (content?.includes(group.oldCmd)) {
254+
content = content.replace(group.oldCmd, group.newCmd);
255+
fs.writeFile(path, content);
256+
}
257+
}
258+
}
259+
}
263260
}
264261

265262
function createNpmrc(

spec/unit/update-spec.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,25 @@ title = 'igniteui-angular example';
308308
- run: echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
309309
- run: npm i # replace with 'npm ci' after committing lock file from first install
310310
# end content
311+
`},
312+
{
313+
path: ".azure/workflows/azure-pipelines.yml",
314+
content:
315+
`# start content
316+
- script: npm i # replace with 'npm ci' after committing lock file from first install
317+
# end content
318+
`,
319+
expected:
320+
`# start content
321+
- script: |
322+
echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
323+
echo "//packages.infragistics.com/npm/js-licensed/:_auth=$NPM_AUTH_TOKEN" >> ~/.npmrc
324+
echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
325+
displayName: 'Authenticate'
326+
env:
327+
NPM_AUTH_TOKEN: $(NPM_AUTH_TOKEN)
328+
- script: npm i # replace with 'npm ci' after committing lock file from first install
329+
# end content
311330
`}];
312331
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
313332
([ "package.json" ], // root package.json
@@ -611,6 +630,25 @@ export default function Home() {
611630
- run: npm i # replace with 'npm ci' after committing lock file from first install
612631
# end content
613632
`},
633+
{
634+
path: ".azure/workflows/azure-pipelines.yml",
635+
content:
636+
`# start content
637+
- script: npm i # replace with 'npm ci' after committing lock file from first install
638+
# end content
639+
`,
640+
expected:
641+
`# start content
642+
- script: |
643+
echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
644+
echo "//packages.infragistics.com/npm/js-licensed/:_auth=$NPM_AUTH_TOKEN" >> ~/.npmrc
645+
echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
646+
displayName: 'Authenticate'
647+
env:
648+
NPM_AUTH_TOKEN: $(NPM_AUTH_TOKEN)
649+
- script: npm i # replace with 'npm ci' after committing lock file from first install
650+
# end content
651+
`},
614652
{
615653
path: "index.html",
616654
content:
@@ -655,7 +693,7 @@ export default function Home() {
655693
</body>
656694
<script type="module" src="/src/main.tsx"></script>
657695
</html>`
658-
},];
696+
}];
659697
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
660698
([ "package.json" ], // root package.json
661699
["index.html"], // html file
@@ -956,6 +994,25 @@ export default class App extends LitElement {
956994
- run: npm i # replace with 'npm ci' after committing lock file from first install
957995
# end content
958996
`},
997+
{
998+
path: ".azure/workflows/azure-pipelines.yml",
999+
content:
1000+
`# start content
1001+
- script: npm i # replace with 'npm ci' after committing lock file from first install
1002+
# end content
1003+
`,
1004+
expected:
1005+
`# start content
1006+
- script: |
1007+
echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
1008+
echo "//packages.infragistics.com/npm/js-licensed/:_auth=$NPM_AUTH_TOKEN" >> ~/.npmrc
1009+
echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
1010+
displayName: 'Authenticate'
1011+
env:
1012+
NPM_AUTH_TOKEN: $(NPM_AUTH_TOKEN)
1013+
- script: npm i # replace with 'npm ci' after committing lock file from first install
1014+
# end content
1015+
`},
9591016
{
9601017
path: "index.html",
9611018
content:

0 commit comments

Comments
 (0)