mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 01:07:01 +08:00
Fixed: 1293772 Change-Id: I0c12c27c66fcab491fac6869f282b3059e16ee9b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3439239 Auto-Submit: Takuto Ikuta <tikuta@chromium.org> Reviewed-by: Tim Van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
90 lines
3.3 KiB
JavaScript
90 lines
3.3 KiB
JavaScript
// Copyright 2022 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
const {assert} = require('chai');
|
|
const path = require('path');
|
|
|
|
const {devtoolsPlugin, esbuildPlugin} = require('../devtools_plugin.js');
|
|
|
|
describe('devtools_plugin can compute paths with', () => {
|
|
it('same directory import', () => {
|
|
assert.deepEqual(
|
|
devtoolsPlugin('./AnotherFile.js', 'front_end/core/sdk/FirstFile.js'),
|
|
{id: path.join('front_end', 'core', 'sdk', 'AnotherFile.js'), external: false});
|
|
});
|
|
|
|
it('different directory import', () => {
|
|
assert.deepEqual(
|
|
devtoolsPlugin('../common/common.js', 'front_end/core/sdk/FirstFile.js'),
|
|
{id: path.join('front_end', 'core', 'common', 'common.js'), external: true});
|
|
});
|
|
|
|
it('node built-in modules', () => {
|
|
assert.deepEqual(devtoolsPlugin('fs', 'scripts/some-script.js'), {id: 'fs', external: true});
|
|
});
|
|
|
|
it('importing generated files', () => {
|
|
assert.strictEqual(devtoolsPlugin('../../generated/Protocol.js', 'front_end/core/sdk/FirstFile.js'), null);
|
|
});
|
|
|
|
it('importing lighthouse files', () => {
|
|
assert.deepEqual(
|
|
devtoolsPlugin('./front_end/third_party/lighthouse/lighthouse-dt-bundle.js', 'front_end/core/sdk/FirstFile.js'),
|
|
{
|
|
id: path.join(
|
|
'front_end', 'core', 'sdk', 'front_end', 'third_party', 'lighthouse', 'lighthouse-dt-bundle.js'),
|
|
external: true,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('esbuild_plugin can compute paths with', () => {
|
|
const srcdir = __dirname;
|
|
const outdir = path.join(srcdir, 'out');
|
|
const plugin = esbuildPlugin(outdir);
|
|
it('same directory import', () => {
|
|
assert.deepEqual(
|
|
plugin({path: './AnotherFile.js', importer: path.join(srcdir, 'front_end/core/sdk/FirstFile.js')}),
|
|
{path: path.join(srcdir, 'front_end', 'core', 'sdk', 'AnotherFile.js')});
|
|
});
|
|
|
|
it('different directory import', () => {
|
|
assert.deepEqual(
|
|
plugin({path: '../common/common.js', importer: path.join(srcdir, 'front_end/core/sdk/FirstFile.js')}),
|
|
{path: './' + path.join('..', 'front_end', 'core', 'common', 'common.js'), external: true});
|
|
});
|
|
|
|
it('node built-in modules', () => {
|
|
assert.deepEqual(
|
|
plugin({path: 'fs', importer: path.join(srcdir, 'scripts/some-script.js')}), {path: 'fs', external: true});
|
|
});
|
|
|
|
it('codemirror modules', () => {
|
|
assert.deepEqual(
|
|
plugin({path: '../../lib/codemirror', importer: path.join(srcdir, 'scripts/some-script.js')}),
|
|
{path: '../../lib/codemirror', external: true});
|
|
});
|
|
|
|
it('importing generated files', () => {
|
|
assert.strictEqual(
|
|
plugin({path: '../../generated/Protocol.js', importer: path.join(srcdir, 'front_end/core/sdk/FirstFile.js')}),
|
|
null);
|
|
});
|
|
|
|
it('importing lighthouse files', () => {
|
|
assert.deepEqual(
|
|
plugin({
|
|
path: './front_end/third_party/lighthouse/lighthouse-dt-bundle.js',
|
|
importer: path.join(srcdir, 'front_end/core/sdk/FirstFile.js')
|
|
}),
|
|
{
|
|
path: './' +
|
|
path.join(
|
|
'..', 'front_end', 'core', 'sdk', 'front_end', 'third_party', 'lighthouse',
|
|
'lighthouse-dt-bundle.js'),
|
|
external: true,
|
|
});
|
|
});
|
|
});
|