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

refactor: migrate to ESM #7331

Merged
merged 19 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
File renamed without changes.
27 changes: 14 additions & 13 deletions .webpack/webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* global __dirname module */

/*
This is the OpenMCT common webpack file. It is imported by the other three webpack configurations:
- webpack.prod.js - the production configuration for OpenMCT (default)
Expand All @@ -8,27 +6,30 @@ This is the OpenMCT common webpack file. It is imported by the other three webpa
There are separate npm scripts to use these configurations, though simply running `npm install`
will use the default production configuration.
*/
const path = require('path');
const packageDefinition = require('../package.json');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
import path from 'node:path';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import webpack from 'webpack';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import fs from 'node:fs';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';

const { VueLoaderPlugin } = require('vue-loader');
import { VueLoaderPlugin } from 'vue-loader';
let gitRevision = 'error-retrieving-revision';
let gitBranch = 'error-retrieving-branch';

const packageDefinition = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));

try {
gitRevision = require('child_process').execSync('git rev-parse HEAD').toString().trim();
gitBranch = require('child_process')
.execSync('git rev-parse --abbrev-ref HEAD')
gitRevision = execSync('git rev-parse HEAD').toString().trim();
gitBranch = execSync('git rev-parse --abbrev-ref HEAD')
.toString()
.trim();
} catch (err) {
console.warn(err);
}

const projectRootDir = path.resolve(__dirname, '..');
const projectRootDir = fileURLToPath(new URL('../', import.meta.url));

/** @type {import('webpack').Configuration} */
const config = {
Expand Down Expand Up @@ -183,4 +184,4 @@ const config = {
}
};

module.exports = config;
export default config;
6 changes: 2 additions & 4 deletions .webpack/webpack.coverage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/* global module */

/*
This file extends the webpack.dev.js config to add babel istanbul coverage.
OpenMCT Continuous Integration servers use this configuration to add code coverage
information to pull requests.
*/

const config = require('./webpack.dev');
import config from './webpack.dev.js';
// eslint-disable-next-line no-undef
const CI = process.env.CI === 'true';

Expand Down Expand Up @@ -34,4 +32,4 @@ config.module.rules.push({
}
});

module.exports = config;
export default config;
14 changes: 7 additions & 7 deletions .webpack/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ This configuration should be used for development purposes. It contains full sou
devServer (which be invoked using by `npm start`), and a non-minified Vue.js distribution.
If OpenMCT is to be used for a production server, use webpack.prod.js instead.
*/
const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
import path from 'path';
import webpack from 'webpack';
import { merge } from 'webpack-merge';
import { fileURLToPath } from 'node:url';

const common = require('./webpack.common');
const projectRootDir = path.resolve(__dirname, '..');
import common from './webpack.common.js';

module.exports = merge(common, {
export default merge(common, {
mode: 'development',
watchOptions: {
// Since we use require.context, webpack is watching the entire directory.
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports = merge(common, {
},
watchFiles: ['**/*.css'],
static: {
directory: path.join(__dirname, '..', '/dist'),
directory: fileURLToPath(new URL('../dist', import.meta.url)),
publicPath: '/dist',
watch: false
}
Expand Down
13 changes: 5 additions & 8 deletions .webpack/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/* global __dirname module */

/*
This configuration should be used for production installs.
It is the default webpack configuration.
*/
const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');

const common = require('./webpack.common');
const projectRootDir = path.resolve(__dirname, '..');
import webpack from 'webpack';
import { merge } from 'webpack-merge';

import common from './webpack.common.js';

module.exports = merge(common, {
export default merge(common, {
mode: 'production',
plugins: [
new webpack.DefinePlugin({
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ The following contains a list of tips and tricks which don't exactly fit into a
It is possible to override the browser's clock in order to control time-based elements. Since this can cause unwanted behavior (i.e. Tree not rendering), only use this sparingly. To do this, use the `overrideClock` fixture as such:

```js
const { test, expect } = require('../../pluginFixtures.js');
import { test, expect } from '../../pluginFixtures.js';

test.describe('foo test suite', () => {

Expand Down
6 changes: 3 additions & 3 deletions e2e/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
* @property {import('../src/api/notifications/NotificationAPI').NotificationOptions} [notificationOptions] additional options
*/

const Buffer = require('buffer').Buffer;
const genUuid = require('uuid').v4;
const { expect } = require('@playwright/test');
import { expect } from '@playwright/test';
import { Buffer } from 'buffer';
import { v4 as genUuid } from 'uuid';

/**
* This common function creates a domain object with the default options. It is the preferred way of creating objects
Expand Down
9 changes: 5 additions & 4 deletions e2e/avpFixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
* existing ones.
*/

const fs = require('fs');
const path = require('path');
const { test, expect } = require('./pluginFixtures');
const AxeBuilder = require('@axe-core/playwright').default;
import AxeBuilder from '@axe-core/playwright';
import fs from 'fs';
import path from 'path';

import { expect, test } from './pluginFixtures.js';

// Constants for repeated values
const TEST_RESULTS_DIR = './test-results';
Expand Down
10 changes: 5 additions & 5 deletions e2e/baseFixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
* GitHub issues.
*/

const base = require('@playwright/test');
import base from '@playwright/test';
const { expect, request } = base;
const fs = require('fs');
const path = require('path');
const { v4: uuid } = require('uuid');
const sinon = require('sinon');
import fs from 'fs';
import path from 'path';
import sinon from 'sinon';
import { v4 as uuid } from 'uuid';

/**
* Takes a `ConsoleMessage` and returns a formatted string. Used to enable console log error detection.
Expand Down
2 changes: 1 addition & 1 deletion e2e/helper/faultUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/
/* global __dirname */
const path = require('path');
import path from 'path';

/**
* @param {import('@playwright/test').Page} page
Expand Down
4 changes: 2 additions & 2 deletions e2e/helper/notebookUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

const { createDomainObjectWithDefaults } = require('../appActions');
import { createDomainObjectWithDefaults } from '../appActions.js';

const NOTEBOOK_DROP_AREA = '.c-notebook__drag-area';
const CUSTOM_NAME = 'CUSTOM_NAME';
const path = require('path');
import path from 'path';

/**
* @param {import('@playwright/test').Page} page
Expand Down
2 changes: 1 addition & 1 deletion e2e/helper/planningUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

import { expect } from '../pluginFixtures';
import { expect } from '../pluginFixtures.js';

/**
* Asserts that the number of activities in the plan view matches the number of
Expand Down
4 changes: 2 additions & 2 deletions e2e/helper/plotTagsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

import { expect } from '../pluginFixtures';
const { waitForPlotsToRender } = require('../appActions');
import { waitForPlotsToRender } from '../appActions.js';
import { expect } from '../pluginFixtures.js';

/**
* Given a canvas and a set of points, tags the points on the canvas.
Expand Down
2 changes: 1 addition & 1 deletion e2e/playwright-ci.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @ts-check

// eslint-disable-next-line no-unused-vars
const { devices } = require('@playwright/test');
import { devices } from '@playwright/test';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import devices.
const MAX_FAILURES = 5;
const NUM_WORKERS = 2;

Expand Down
2 changes: 1 addition & 1 deletion e2e/playwright-local.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @ts-check

// eslint-disable-next-line no-unused-vars
const { devices } = require('@playwright/test');
import { devices } from '@playwright/test';

/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
Expand Down
2 changes: 1 addition & 1 deletion e2e/playwright-watch.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @ts-check

// eslint-disable-next-line no-unused-vars
const { devices } = require('@playwright/test');
import { devices } from '@playwright/test';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import devices.
const MAX_FAILURES = 5;
const NUM_WORKERS = 2;

Expand Down
7 changes: 4 additions & 3 deletions e2e/pluginFixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
* and appActions. These fixtures should be generalized across all plugins.
*/

const { test, expect, request } = require('./baseFixtures');
// const { createDomainObjectWithDefaults } = require('./appActions');
const path = require('path');
// import { createDomainObjectWithDefaults } from './appActions.js';
import path from 'path';

import { expect, request, test } from './baseFixtures.js';

/**
* @typedef {Object} ObjectCreateOptions
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/framework/appActions.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

const { test, expect } = require('../../pluginFixtures.js');
const {
import {
createDomainObjectWithDefaults,
createNotification,
expandEntireTree
} = require('../../appActions.js');
} from '../../appActions.js';
import { expect, test } from '../../pluginFixtures.js';

test.describe('AppActions', () => {
test('createDomainObjectsWithDefaults', async ({ page }) => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/framework/baseFixtures.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ relates to how we've extended it (i.e. ./e2e/baseFixtures.js) and assumptions ma
(`npm start` and ./e2e/webpack-dev-middleware.js)
*/

const { test } = require('../../baseFixtures.js');
import { test } from '../../baseFixtures.js';

test.describe('baseFixtures tests', () => {
//Skip this test for now https://github.com/nasa/openmct/issues/6785
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/framework/exampleTemplate.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
*/

// Structure: Some standard Imports. Please update the required pathing.
const { test, expect } = require('../../pluginFixtures');
const { createDomainObjectWithDefaults } = require('../../appActions');
import { createDomainObjectWithDefaults } from '../../appActions.js';
import { expect, test } from '../../pluginFixtures.js';

/**
* Structure:
Expand Down
12 changes: 5 additions & 7 deletions e2e/tests/framework/generateLocalStorageData.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
* and is additionally verified in the validation test suites below.
*/

const { test, expect } = require('../../pluginFixtures.js');
const {
createDomainObjectWithDefaults,
createExampleTelemetryObject
} = require('../../appActions.js');
const { MISSION_TIME } = require('../../constants.js');
const path = require('path');
import path from 'path';

import { createDomainObjectWithDefaults, createExampleTelemetryObject } from '../../appActions.js';
import { MISSION_TIME } from '../../constants.js';
import { expect, test } from '../../pluginFixtures.js';

const overlayPlotName = 'Overlay Plot with Telemetry Object';

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/framework/pluginFixtures.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This test suite is dedicated to testing our use of our custom fixtures to verify
that they are working as expected.
*/

const { test } = require('../../pluginFixtures.js');
import { test } from '../../pluginFixtures.js';

// eslint-disable-next-line playwright/no-skipped-test
test.describe.skip('pluginFixtures tests', () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/functional/branding.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
This test suite is dedicated to tests which verify branding related components.
*/

const { test, expect } = require('../../baseFixtures.js');
import { expect, test } from '../../baseFixtures.js';

test.describe('Branding tests', () => {
test('About Modal launches with basic branding properties', async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/functional/clearDataAction.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
Verify that the "Clear Data" menu action performs as expected for various object types.
*/

const { test, expect } = require('../../pluginFixtures.js');
const { createDomainObjectWithDefaults } = require('../../appActions.js');
import { createDomainObjectWithDefaults } from '../../appActions.js';
import { expect, test } from '../../pluginFixtures.js';

const backgroundImageSelector = '.c-imagery__main-image__background-image';

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/functional/couchdb.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
*/

const { test, expect } = require('../../pluginFixtures');
import { expect, test } from '../../pluginFixtures.js';

test.describe('CouchDB Status Indicator with mocked responses @couchdb', () => {
test.use({ failOnConsoleError: false });
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/functional/example/eventGenerator.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
This test suite is dedicated to tests which verify the basic operations surrounding the example event generator.
*/

const { test, expect } = require('../../../pluginFixtures');
const { createDomainObjectWithDefaults } = require('../../../appActions');
import { createDomainObjectWithDefaults } from '../../../appActions.js';
import { expect, test } from '../../../pluginFixtures.js';

test.describe('Example Event Generator CRUD Operations', () => {
test('Can create a Test Event Generator and it results in the table View', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
This test suite is dedicated to tests which verify the basic operations surrounding conditionSets.
*/

const { test, expect } = require('../../../../baseFixtures');
import { expect, test } from '../../../../baseFixtures.js';

test.describe('Sine Wave Generator', () => {
test('Create new Sine Wave Generator Object and validate create Form Logic', async ({
Expand Down
9 changes: 5 additions & 4 deletions e2e/tests/functional/forms.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
This test suite is dedicated to tests which verify form functionality in isolation
*/

const { test, expect } = require('../../pluginFixtures');
const { createDomainObjectWithDefaults } = require('../../appActions');
const genUuid = require('uuid').v4;
const path = require('path');
import path from 'path';
import { v4 as genUuid } from 'uuid';

import { createDomainObjectWithDefaults } from '../../appActions.js';
import { expect, test } from '../../pluginFixtures.js';

const TEST_FOLDER = 'test folder';
const jsonFilePath = 'e2e/test-data/ExampleLayouts.json';
Expand Down
Loading
Loading