Skip to content

Commit

Permalink
Verify no warnings if pinned to a node version (GoogleCloudPlatform#139)
Browse files Browse the repository at this point in the history
Adds tests that verify that if a node version is specified in
`package.json`, then no warnings are emitted that state how to
pin to a node version.
  • Loading branch information
DominicKramer authored Oct 16, 2017
1 parent 3b30447 commit 9c40cf1
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions builder/steps/gen-dockerfile/contents/test/detect_setup_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ function eachOf(expectedLogs: string[]): StringArrayVerifier {
};
}

function noneOf(givenLogs: string[]): StringArrayVerifier {
return (acutalLogs: string[]) => {
const notExpected = new Set(givenLogs);
const found = new Set();
for (let actual of acutalLogs) {
if (notExpected.has(actual)) {
found.add(actual);
}
}

assert.deepEqual(Array.from(found), []);
};
}

describe('detectSetup', () => {
function performTest(testConfig: TestConfig) {
it(testConfig.title, async () => {
Expand Down Expand Up @@ -767,6 +781,28 @@ describe('detectSetup', () => {
}
});

performTest({
title: 'should not warn of node version if pinned to a node version',
locations: [
{
path: 'package.json',
exists: true,
contents: JSON.stringify({engines: {node: 'something'}})
},
{path: 'server.js', exists: true, contents: SERVER_JS_CONTENTS},
{path: 'app.yaml', exists: true, contents: VALID_APP_YAML_CONTENTS},
{path: 'yarn.lock', exists: false},
{path: 'package-lock.json', exists: false}
],
expectedErrors: noneOf([NODE_VERSION_WARNING]),
expectedResult: {
canInstallDeps: true,
nodeVersion: 'something',
useYarn: false,
appYamlPath: DEFAULT_APP_YAML
}
});

performTest({
title: 'should warn of upcoming Node version update with package.json',
locations: [
Expand Down Expand Up @@ -800,5 +836,28 @@ describe('detectSetup', () => {
appYamlPath: DEFAULT_APP_YAML
}
});

performTest({
title: 'should not warn of upcoming Node version update if pinned ' +
'to a node version',
locations: [
{
path: 'package.json',
exists: true,
contents: JSON.stringify({engines: {node: 'something'}})
},
{path: 'server.js', exists: true, contents: SERVER_JS_CONTENTS},
{path: 'app.yaml', exists: true, contents: VALID_APP_YAML_CONTENTS},
{path: 'yarn.lock', exists: false},
{path: 'package-lock.json', exists: false}
],
expectedErrors: noneOf([NODE_TO_UPDATE_WARNING]),
expectedResult: {
canInstallDeps: true,
nodeVersion: 'something',
useYarn: false,
appYamlPath: DEFAULT_APP_YAML
}
});
});
});

0 comments on commit 9c40cf1

Please sign in to comment.