Path: blob/trunk/javascript/selenium-webdriver/lib/test/resources.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819const fs = require('node:fs')20const path = require('node:path')21const runfiles = require('@bazel/runfiles')22const { projectRoot } = require('./build')2324// PUBLIC API2526/**27* Locates a test resource.28* @param {string} filePath The file to locate from the root of the project.29* @return {string} The full path for the file, if it exists.30* @throws {Error} If the file does not exist.31*/32exports.locate = function (filePath) {33const fullPath = path.normalize(path.join(projectRoot(), filePath))34if (fs.existsSync(fullPath)) {35return fullPath36}3738try {39return runfiles.resolve(filePath)40} catch {41// Fall through42}4344throw Error('File does not exist: ' + filePath)45}464748