mirror of
https://gitea.com/actions/setup-node.git
synced 2024-11-22 10:09:33 +01:00
adding test case
This commit is contained in:
parent
2b1e32b119
commit
60b802d0e8
3 changed files with 66 additions and 18 deletions
|
@ -294,6 +294,63 @@ describe('run', () => {
|
||||||
);
|
);
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('save with -1 cacheId , should not fail workflow', async () => {
|
||||||
|
inputs['cache'] = 'npm';
|
||||||
|
getStateSpy.mockImplementation((name: string) => {
|
||||||
|
if (name === State.CacheMatchedKey) {
|
||||||
|
return npmFileHash;
|
||||||
|
} else {
|
||||||
|
return yarnFileHash;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`);
|
||||||
|
saveCacheSpy.mockImplementation(() => {
|
||||||
|
return -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
await run();
|
||||||
|
|
||||||
|
expect(getInputSpy).toHaveBeenCalled();
|
||||||
|
expect(getStateSpy).toHaveBeenCalledTimes(2);
|
||||||
|
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(debugSpy).toHaveBeenCalledWith(`npm path is ${commonPath}/npm`);
|
||||||
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
||||||
|
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
|
||||||
|
);
|
||||||
|
expect(saveCacheSpy).toHaveBeenCalled();
|
||||||
|
expect(infoSpy).not.toHaveBeenLastCalledWith(
|
||||||
|
`Cache saved with the key: ${yarnFileHash}`
|
||||||
|
);
|
||||||
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('saves with error from toolkit, should fail workflow', async () => {
|
||||||
|
inputs['cache'] = 'npm';
|
||||||
|
getStateSpy.mockImplementation((name: string) => {
|
||||||
|
if (name === State.CacheMatchedKey) {
|
||||||
|
return npmFileHash;
|
||||||
|
} else {
|
||||||
|
return yarnFileHash;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`);
|
||||||
|
saveCacheSpy.mockImplementation(() => {
|
||||||
|
throw new cache.ValidationError('Validation failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
await run();
|
||||||
|
|
||||||
|
expect(getInputSpy).toHaveBeenCalled();
|
||||||
|
expect(getStateSpy).toHaveBeenCalledTimes(2);
|
||||||
|
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(debugSpy).toHaveBeenCalledWith(`npm path is ${commonPath}/npm`);
|
||||||
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
||||||
|
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
|
||||||
|
);
|
||||||
|
expect(saveCacheSpy).toHaveBeenCalled();
|
||||||
|
expect(setFailedSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|
13
dist/cache-save/index.js
vendored
13
dist/cache-save/index.js
vendored
|
@ -59888,16 +59888,11 @@ const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, func
|
||||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
const cacheId = yield cache.saveCache([cachePath], primaryKey);
|
||||||
const cacheId = yield cache.saveCache([cachePath], primaryKey);
|
if (cacheId == -1) {
|
||||||
if (cacheId == -1) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
core.warning(`${error.message}`);
|
|
||||||
}
|
}
|
||||||
|
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||||
});
|
});
|
||||||
run();
|
run();
|
||||||
|
|
||||||
|
|
|
@ -49,16 +49,12 @@ const cachePackages = async (packageManager: string) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const cacheId = await cache.saveCache([cachePath], primaryKey);
|
||||||
const cacheId = await cache.saveCache([cachePath], primaryKey);
|
if (cacheId == -1) {
|
||||||
if (cacheId == -1) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
|
||||||
} catch (error) {
|
|
||||||
core.warning(`${error.message}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
Loading…
Reference in a new issue