Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(chrome-source): add test for chrome-source.js #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tests/lib/chrome-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import test from 'ava';
import {tmpdir} from 'os';
import { urlFor, fetchAllTo } from '../../tools/lib/chrome-source.js';

const revision = '23a41c068e35f33df1c3579a3b0b469d4458e6c1';
const chromePath = 'chrome/common/apps/platform_apps/api';
const chromePaths = [
'tools/json_schema_compiler',
'tools/json_schema_compiler/test',
'tools/json_comment_eater',
'ppapi/generators',
'third_party/ply',
];

test('urlFor', (t) => {
// Returns valid url
const uf = urlFor(revision, chromePath);
t.is(uf.startsWith('https://'), true);
t.is(uf.includes(revision), true);
t.is(uf.endsWith(`${chromePath}.tar.gz`), true);
});

test('fetchAllTo', async (t) => {
let fta;
// Returns chrome source tree files for each path
fta = await fetchAllTo(tmpdir(), chromePaths, revision);
t.is(Array.isArray(fta), true);
t.is(fta.length, chromePaths.length);

// Throws error with invalid arguments
// @ts-ignore
await t.throwsAsync(() => fetchAllTo(null, chromePaths, revision));
// @ts-ignore
t.throws(() => fetchAllTo(tmpdir(), null, revision));
// @ts-ignore
await t.throwsAsync(() => fetchAllTo(tmpdir(), chromePaths, null));
});
4 changes: 2 additions & 2 deletions tools/lib/chrome-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import fetch from 'node-fetch';
* @param {string} chromePath
* @return {string}
*/
function urlFor(revision, chromePath) {
export function urlFor(revision, chromePath) {
return `https://chromium.googlesource.com/chromium/src/+archive/${revision}/${chromePath}.tar.gz`;
}

Expand All @@ -46,7 +46,7 @@ function urlFor(revision, chromePath) {
* @param {string} revision revision to fetch
* @return {Promise<(string[]?)[]>} files written for paths, null for skipped
*/
export async function fetchAllTo(targetPath, chromePaths, revision) {
export function fetchAllTo(targetPath, chromePaths, revision) {
// This removes any trailing "/" from the paths.
chromePaths = chromePaths.map(chromePath => path.join(chromePath, '.'));

Expand Down