@helsenorge/library-build 30.0.2 → 32.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ const parentBabelConfig = {
2
+ presets: [
3
+ ['@babel/preset-env', { targets: { node: 'current' } }],
4
+ ['@babel/preset-react', { typescript: true, runtime: 'automatic' }],
5
+ ['@babel/preset-typescript', { allExtensions: true, isTSX: true }],
6
+ ],
7
+ plugins: [
8
+ '@babel/plugin-syntax-dynamic-import',
9
+ ['@babel/plugin-proposal-class-properties', { loose: true }],
10
+ '@babel/plugin-transform-object-rest-spread',
11
+ ],
12
+ };
13
+
14
+ module.exports = parentBabelConfig;
@@ -1,31 +1,29 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2015",
4
- "module": "ES2020",
5
- "moduleResolution": "node",
6
- "sourceMap": true,
7
- "jsx": "react",
8
- "suppressImplicitAnyIndexErrors": true,
9
- "allowSyntheticDefaultImports": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "esModuleInterop": true,
12
- "newLine": "LF",
13
- "allowUnreachableCode": false,
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
14
7
  "skipLibCheck": true,
15
- "lib": ["es5", "es2015.core", "es2015.promise", "es6", "dom", "scripthost"],
16
- "noEmit": false,
17
- "importHelpers": true,
18
- "declaration": true,
19
- "declarationMap": true,
20
- "removeComments": false,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "node",
11
+ "allowImportingTsExtensions": false,
21
12
  "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": false,
15
+ "jsx": "react-jsx",
22
16
 
23
17
  /* Linting */
24
18
  "strict": true,
25
19
  "noUnusedLocals": true,
26
20
  "noUnusedParameters": true,
27
21
  "noFallthroughCasesInSwitch": true,
28
- "noImplicitAny": true, // noImplicitAny og strictNullChecks er skrudd på i tilfelle noen extender configen og setter strict til false
29
- "strictNullChecks": true
22
+
23
+ /* library-build specific options */
24
+ "declaration": true,
25
+ "declarationMap": true,
26
+
27
+ "esModuleInterop": true
30
28
  }
31
29
  }
package/copy.js CHANGED
@@ -1,28 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var path_1 = require("path");
5
- var copyfiles_1 = tslib_1.__importDefault(require("copyfiles"));
6
- var rimraf_1 = require("rimraf");
7
- var yargs_1 = tslib_1.__importDefault(require("yargs"));
8
- var helpers_1 = require("yargs/helpers");
9
- var files_1 = require("./files");
10
- var _a = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
1
+ import { createRequire } from 'node:module';
2
+ import path from 'path';
3
+ import copyfiles from 'copyfiles';
4
+ import { rimraf } from 'rimraf';
5
+ import yargs from 'yargs';
6
+ import { hideBin } from 'yargs/helpers';
7
+ const require = createRequire(import.meta.url);
8
+ import { createPackageJsonFile } from './files.js';
9
+ const { root, include, utils, rm } = yargs(hideBin(process.argv))
11
10
  .options({
12
11
  root: { describe: 'Files to copy to root directory', type: 'array', default: [] },
13
12
  include: { describe: 'Files to copy from src to lib, replacing "src" with "lib"', type: 'array', default: [] },
14
13
  utils: { describe: 'Files to copy to lib/utils', type: 'array', default: [] },
15
- rm: { describe: 'Files to delete', type: 'string', default: '' },
14
+ rm: { describe: 'Files to delete', type: 'array', default: [] },
16
15
  })
17
- .parse(), root = _a.root, include = _a.include, utils = _a.utils, rm = _a.rm;
18
- var originalPackageJson = (0, path_1.resolve)(process.cwd(), 'package.json');
19
- var _b = require(originalPackageJson), packageName = _b.name, outputDirectory = _b.publishConfig.directory;
20
- var outputPath = (0, path_1.resolve)(process.cwd(), outputDirectory);
21
- var newPackageJson = (0, path_1.resolve)(outputPath, 'package.json');
16
+ .parse();
17
+ const originalPackageJson = path.resolve(process.cwd(), 'package.json');
18
+ const { name: packageName, publishConfig: { directory: outputDirectory }, } = require(originalPackageJson);
19
+ const outputPath = path.resolve(process.cwd(), outputDirectory);
20
+ const newPackageJson = path.resolve(outputPath, 'package.json');
22
21
  Promise.all([
23
- (0, copyfiles_1.default)(tslib_1.__spreadArray(tslib_1.__spreadArray([], root, true), [outputPath], false), console.error),
24
- (0, copyfiles_1.default)(tslib_1.__spreadArray(tslib_1.__spreadArray([], include, true), [outputPath], false), { up: 1 }, console.error),
25
- (0, copyfiles_1.default)(tslib_1.__spreadArray(tslib_1.__spreadArray([], utils, true), [(0, path_1.resolve)(outputPath, 'utils')], false), { up: true }, console.error),
22
+ new Promise((resolve, reject) => copyfiles([...root, outputPath], e => (e ? reject(e) : resolve()))),
23
+ new Promise((resolve, reject) => copyfiles([...include, outputPath], { up: 1 }, e => (e ? reject(e) : resolve()))),
24
+ new Promise((resolve, reject) => copyfiles([...utils, path.resolve(outputPath, 'utils')], { up: true }, e => (e ? reject(e) : resolve()))),
26
25
  ])
27
- .then(function () { return (rm ? (0, rimraf_1.rimraf)(rm) : Promise.resolve(true)); })
28
- .then(function () { return (0, files_1.createPackageJsonFile)(packageName, originalPackageJson, newPackageJson); });
26
+ .then(() => (rm ? rimraf(rm) : Promise.resolve(true)))
27
+ .then(() => createPackageJsonFile(packageName, originalPackageJson, newPackageJson));
package/files.d.ts CHANGED
@@ -2,5 +2,5 @@
2
2
  * Function used to create the package.json file under /lib
3
3
  * @param packageName - the name field in package.json (for example: @helsenorge/step')
4
4
  */
5
- export declare function createPackageJsonFile(packageName: string, inputPath: string, outputPath: string): Promise<unknown>;
5
+ export declare function createPackageJsonFile(packageName: string, inputPath: string, outputPath: string): Promise<string>;
6
6
  //# sourceMappingURL=files.d.ts.map
package/files.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAwC/F"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2CjH"}
package/files.js CHANGED
@@ -1,48 +1,47 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPackageJsonFile = void 0;
4
- var fs_1 = require("fs");
1
+ import { readFile, writeFile } from 'fs';
5
2
  /**
6
3
  * Function used to create the package.json file under /lib
7
4
  * @param packageName - the name field in package.json (for example: @helsenorge/step')
8
5
  */
9
- function createPackageJsonFile(packageName, inputPath, outputPath) {
10
- return new Promise(function (resolve) {
11
- (0, fs_1.readFile)(inputPath, 'utf8', function (err, data) {
6
+ export function createPackageJsonFile(packageName, inputPath, outputPath) {
7
+ return new Promise((resolve) => {
8
+ readFile(inputPath, 'utf8', (err, data) => {
12
9
  if (err) {
13
10
  throw err;
14
11
  }
15
12
  resolve(data);
16
13
  });
17
14
  })
18
- .then(function (data) { return JSON.parse(data); })
19
- .then(function (packageData) {
20
- var author = packageData.author, version = packageData.version, repository = packageData.repository, bin = packageData.bin, peerDependencies = packageData.peerDependencies, license = packageData.license, dependencies = packageData.dependencies, publishConfig = packageData.publishConfig;
21
- var minimalPackage = {
15
+ .then((data) => JSON.parse(data))
16
+ .then((packageData) => {
17
+ const { author, version, main, sideEffects, repository, bin, peerDependencies, license, dependencies, publishConfig } = packageData;
18
+ const minimalPackage = {
22
19
  name: packageName,
23
- author: author,
24
- version: version,
25
- main: './index.js',
26
- repository: repository,
27
- bin: bin,
28
- license: license,
29
- peerDependencies: peerDependencies,
30
- dependencies: dependencies,
20
+ author,
21
+ version,
22
+ main,
23
+ type: ['@helsenorge/core-build', '@helsenorge/library-build'].includes(packageName) ? 'module' : undefined,
24
+ sideEffects,
25
+ repository,
26
+ bin,
27
+ license,
28
+ peerDependencies,
29
+ dependencies,
31
30
  };
32
- if (publishConfig === null || publishConfig === void 0 ? void 0 : publishConfig.access) {
31
+ if (publishConfig?.access) {
33
32
  minimalPackage.publishConfig = {
34
33
  access: publishConfig.access,
35
34
  };
36
35
  }
37
- return new Promise(function (resolve) {
38
- var data = JSON.stringify(minimalPackage, null, 2);
39
- (0, fs_1.writeFile)(outputPath, data, function (err) {
36
+ return new Promise(resolve => {
37
+ const data = JSON.stringify(minimalPackage, null, 2);
38
+ writeFile(outputPath, data, err => {
40
39
  if (err)
41
40
  throw err;
42
- console.log("Created package.json in ".concat(outputPath));
41
+ // eslint-disable-next-line no-console
42
+ console.log(`Created package.json in ${outputPath}`);
43
43
  resolve(outputPath);
44
44
  });
45
45
  });
46
46
  });
47
47
  }
48
- exports.createPackageJsonFile = createPackageJsonFile;
package/index.html CHANGED
@@ -1,4 +1,4 @@
1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
  <html lang="no">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
@@ -26,8 +26,8 @@
26
26
  <hn-webcomp-header></hn-webcomp-header>
27
27
  <div id="main-content-wrapper"></div>
28
28
 
29
- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
30
- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
29
+ <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/18.3.1/umd/react.development.js"></script>
30
+ <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.3.1/umd/react-dom.development.js"></script>
31
31
 
32
32
  <!-- IMPORT header-footer script -->
33
33
  <script type="module" src="https://static-hn-mas-01.int-hn.nhn.no/header-footer/static/js/header-footer/header-footer.js"></script>
@@ -1 +1 @@
1
- {"version":3,"file":"jest.config.d.ts","sourceRoot":"","sources":["../src/jest.config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAanC,QAAA,MAAM,MAAM,EAAE,MAuCb,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"jest.config.d.ts","sourceRoot":"","sources":["../src/jest.config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAenC,QAAA,MAAM,MAAM,EAAE,MAsCb,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/jest.config.js CHANGED
@@ -1,21 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
4
3
  /* Legger til babel-jest + esm og babel-jest igjen uner 'transform' for å kunne håndtere esm import/exports */
5
4
  /* Viktig å ha @helsenorge pakker under transformIgnorePatterns fordi de eksporteres i rå esm */
6
- var individualConfig;
7
- var rootDir = process.cwd();
5
+ let individualConfig;
6
+ const rootDir = process.cwd();
8
7
  try {
9
8
  individualConfig = require(rootDir + '/jest.config.cjs');
10
9
  }
11
10
  catch (ex) {
12
11
  console.log('Benytter delt jest.config.js-fil');
13
12
  }
14
- var config = tslib_1.__assign({ rootDir: rootDir, verbose: true, setupFilesAfterEnv: ['<rootDir>/node_modules/@helsenorge/library-build/setupTests.js'], coverageProvider: 'v8', testEnvironment: 'jest-environment-jsdom', testEnvironmentOptions: {
13
+ const config = {
14
+ rootDir,
15
+ verbose: true,
16
+ setupFilesAfterEnv: ['<rootDir>/node_modules/@helsenorge/library-build/setupTests.js'],
17
+ coverageProvider: 'v8',
18
+ testEnvironment: 'jest-environment-jsdom',
19
+ testEnvironmentOptions: {
15
20
  url: 'http://tjenester.helsenorge.utvikling',
16
- }, transform: {
21
+ },
22
+ transform: {
17
23
  '^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
18
- }, transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\](?!@helsenorge[/\\\\])', '^.+\\.module\\.(css|sass|scss|scss.d.ts)$'], coverageReporters: ['cobertura', 'lcov', 'json'], collectCoverage: true, collectCoverageFrom: [
24
+ },
25
+ transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\](?!(@helsenorge)[/\\\\])', '^.+\\.module\\.(css|sass|scss|scss.d.ts)$'],
26
+ coverageReporters: ['cobertura', 'lcov', 'json'],
27
+ collectCoverage: true,
28
+ collectCoverageFrom: [
19
29
  '**/*.ts',
20
30
  '**/*.tsx',
21
31
  '!**/node_modules/**',
@@ -26,9 +36,17 @@ var config = tslib_1.__assign({ rootDir: rootDir, verbose: true, setupFilesAfter
26
36
  '!**/types/**',
27
37
  '!**/constants/*.ts',
28
38
  '!**/*types.ts',
29
- ], moduleNameMapper: {
39
+ ],
40
+ moduleNameMapper: {
30
41
  '\\.(css|scss)$': 'identity-obj-proxy',
31
- }, moduleDirectories: ['node_modules', 'src'],
42
+ },
43
+ moduleDirectories: ['node_modules', 'src'],
32
44
  // Unngå warning om jest-haste-map: Haste module naming collision
33
- modulePathIgnorePatterns: ['lib'], moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'], coveragePathIgnorePatterns: ['^.+\\.module\\.(css|sass|scss|scss.d.ts)$'], testResultsProcessor: 'jest-junit-reporter', snapshotSerializers: ['enzyme-to-json/serializer'], cacheDirectory: '<rootDir>/.jest-cache' }, individualConfig);
34
- exports.default = config;
45
+ modulePathIgnorePatterns: ['lib'],
46
+ moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
47
+ coveragePathIgnorePatterns: ['^.+\\.module\\.(css|sass|scss|scss.d.ts)$'],
48
+ testResultsProcessor: 'jest-junit-reporter',
49
+ cacheDirectory: '<rootDir>/.jest-cache',
50
+ ...individualConfig,
51
+ };
52
+ export default config;
@@ -1,16 +1,16 @@
1
1
  #! /usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- var sync = require('cross-spawn').sync;
5
- var args = process.argv.slice(2);
6
- var scriptIndex = args.findIndex(function (x) { return x === 'start' || x === 'test' || x === 'copy'; });
7
- var script = scriptIndex === -1 ? args[0] : args[scriptIndex];
8
- var nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
2
+ import { createRequire } from 'node:module';
3
+ const require = createRequire(import.meta.url);
4
+ const sync = require('cross-spawn').sync;
5
+ const args = process.argv.slice(2);
6
+ const scriptIndex = args.findIndex(x => x === 'start' || x === 'test' || x === 'copy');
7
+ const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
8
+ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
9
9
  switch (script) {
10
10
  case 'start':
11
11
  case 'test':
12
12
  case 'copy': {
13
- var result = sync('node', nodeArgs.concat(require.resolve('./' + script)).concat(args.slice(scriptIndex + 1)), {
13
+ const result = sync('node', nodeArgs.concat(require.resolve('./' + script)).concat(args.slice(scriptIndex + 1)), {
14
14
  stdio: 'inherit',
15
15
  });
16
16
  if (result.signal) {
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@helsenorge/library-build",
3
3
  "author": "Norsk helsenett SF",
4
- "version": "30.0.2",
5
- "main": "./index.js",
4
+ "version": "32.0.1",
5
+ "type": "module",
6
+ "sideEffects": false,
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "https://github.com/helsenorge/core-frontend-packages"
@@ -11,40 +12,40 @@
11
12
  "library-scripts": "./library-scripts.js"
12
13
  },
13
14
  "license": "MIT",
15
+ "peerDependencies": {
16
+ "react": "^17.0.0 || ^18.0.0",
17
+ "react-dom": "^17.0.0 || ^18.0.0"
18
+ },
14
19
  "dependencies": {
15
- "@babel/core": "^7.23.7",
16
- "@helsenorge/eslint-config": "^30.0.2",
17
- "@testing-library/jest-dom": "^5.17.0",
18
- "@testing-library/react": "^12.1.5",
20
+ "@babel/core": "^7.25.2",
21
+ "@helsenorge/eslint-config": "^32.0.0",
22
+ "@testing-library/jest-dom": "^6.4.8",
23
+ "@testing-library/react": "^16.0.0",
19
24
  "@testing-library/user-event": "^14.5.2",
20
25
  "@types/copyfiles": "^2.4.4",
21
- "@types/enzyme": "^3.10.18",
22
- "@types/enzyme-to-json": "^1.5.7",
23
- "@types/react": "^17.0.74",
24
- "@types/react-dom": "^17.0.25",
25
- "@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
26
+ "@types/react": "^18.3.3",
27
+ "@types/react-dom": "^18.3.0",
28
+ "@vitest/coverage-v8": "^1.6.0",
26
29
  "babel-jest": "^29.7.0",
27
30
  "babel-preset-react-app": "^10.0.1",
28
- "copyfiles": "2.4.1",
29
- "crlf": "1.1.1",
30
- "cross-spawn": "7.0.3",
31
- "enzyme": "^3.11.0",
32
- "enzyme-to-json": "^3.6.2",
33
- "esbuild": "^0.19.11",
34
- "esbuild-sass-plugin": "^2.16.1",
31
+ "copyfiles": "^2.4.1",
32
+ "crlf": "^1.1.1",
33
+ "cross-spawn": "^7.0.3",
34
+ "esbuild": "^0.21.5",
35
+ "esbuild-sass-plugin": "^3.3.1",
35
36
  "identity-obj-proxy": "^3.0.0",
36
- "isomorphic-fetch": "^3.0.0",
37
37
  "jest": "^29.7.0",
38
38
  "jest-environment-jsdom": "^29.7.0",
39
39
  "jest-junit-reporter": "^1.1.0",
40
40
  "jest-resolve": "^29.7.0",
41
- "postcss": "^8.4.33",
41
+ "postcss": "^8.4.41",
42
42
  "postcss-modules": "^6.0.0",
43
- "react": "17.0.2",
44
- "react-dom": "17.0.2",
45
- "rimraf": "^5.0.5",
46
- "tslib": "^2.6.2",
47
- "typescript": "4.9.4"
43
+ "rimraf": "^5.0.10",
44
+ "tslib": "^2.6.3",
45
+ "typed-scss-modules": "^8.0.1",
46
+ "typescript": "^5.5.4",
47
+ "vitest": "^1.6.0",
48
+ "whatwg-fetch": "^3.6.20"
48
49
  },
49
50
  "publishConfig": {
50
51
  "access": "public"
package/setupTests.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import '@testing-library/jest-dom/extend-expect';
2
- import 'isomorphic-fetch';
1
+ import '@testing-library/jest-dom';
2
+ import 'whatwg-fetch';
3
3
  declare global {
4
4
  interface Window {
5
5
  HN: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"setupTests.d.ts","sourceRoot":"","sources":["../src/setupTests.ts"],"names":[],"mappings":"AAIA,OAAO,yCAAyC,CAAC;AACjD,OAAO,kBAAkB,CAAC;AAO1B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC7B;CACF"}
1
+ {"version":3,"file":"setupTests.d.ts","sourceRoot":"","sources":["../src/setupTests.ts"],"names":[],"mappings":"AAIA,OAAO,2BAA2B,CAAC;AACnC,OAAO,cAAc,CAAC;AAEtB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC7B;CACF"}
package/setupTests.js CHANGED
@@ -1,14 +1,64 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
1
  // jest-dom adds custom jest matchers for asserting on DOM nodes.
5
2
  // allows you to do things like:
6
3
  // expect(element).toHaveTextContent(/react/i)
7
4
  // learn more: https://github.com/testing-library/jest-dom
8
- require("@testing-library/jest-dom/extend-expect");
9
- require("isomorphic-fetch");
10
- var enzyme_adapter_react_17_1 = tslib_1.__importDefault(require("@wojtekmaj/enzyme-adapter-react-17"));
11
- var enzyme_1 = require("enzyme");
12
- // configuring enzyme adapter
13
- (0, enzyme_1.configure)({ adapter: new enzyme_adapter_react_17_1.default() });
14
- window.HN = {};
5
+ import '@testing-library/jest-dom';
6
+ import 'whatwg-fetch';
7
+ window.HN = {
8
+ Page: {},
9
+ Rest: {},
10
+ User: {},
11
+ Commands: {},
12
+ PortalCommands: {},
13
+ };
14
+ const mockWindowMatchMedia = jest.fn().mockImplementation(() => ({
15
+ matches: true,
16
+ addEventListener: jest.fn(),
17
+ removeEventListener: jest.fn(),
18
+ }));
19
+ Object.defineProperty(window, 'matchMedia', {
20
+ writable: true,
21
+ value: mockWindowMatchMedia,
22
+ });
23
+ class IntersectionObserver {
24
+ observe() {
25
+ // do nothing
26
+ }
27
+ unobserve() {
28
+ // do nothing
29
+ }
30
+ disconnect() {
31
+ // do nothing
32
+ }
33
+ }
34
+ Object.defineProperty(window, 'IntersectionObserver', {
35
+ writable: true,
36
+ value: IntersectionObserver,
37
+ });
38
+ class ResizeObserver {
39
+ observe() {
40
+ // do nothing
41
+ }
42
+ unobserve() {
43
+ // do nothing
44
+ }
45
+ disconnect() {
46
+ // do nothing
47
+ }
48
+ }
49
+ Object.defineProperty(window, 'ResizeObserver', {
50
+ writable: true,
51
+ value: ResizeObserver,
52
+ });
53
+ class MutationObserver {
54
+ observe() {
55
+ // do nothing
56
+ }
57
+ disconnect() {
58
+ // do nothing
59
+ }
60
+ }
61
+ Object.defineProperty(window, 'MutationObserver', {
62
+ writable: true,
63
+ value: MutationObserver,
64
+ });
@@ -0,0 +1,8 @@
1
+ import '@testing-library/jest-dom';
2
+ import 'whatwg-fetch';
3
+ declare global {
4
+ interface Window {
5
+ HN: Record<string, unknown>;
6
+ }
7
+ }
8
+ //# sourceMappingURL=setupTests.vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupTests.vite.d.ts","sourceRoot":"","sources":["../src/setupTests.vite.ts"],"names":[],"mappings":"AACA,OAAO,2BAA2B,CAAC;AACnC,OAAO,cAAc,CAAC;AAEtB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC7B;CACF"}
@@ -0,0 +1,61 @@
1
+ import { vi } from 'vitest';
2
+ import '@testing-library/jest-dom';
3
+ import 'whatwg-fetch';
4
+ window.HN = {
5
+ Page: {},
6
+ Rest: {},
7
+ User: {},
8
+ Commands: {},
9
+ PortalCommands: {},
10
+ };
11
+ const mockWindowMatchMedia = vi.fn().mockImplementation(() => ({
12
+ matches: true,
13
+ addEventListener: vi.fn(),
14
+ removeEventListener: vi.fn(),
15
+ }));
16
+ Object.defineProperty(window, 'matchMedia', {
17
+ writable: true,
18
+ value: mockWindowMatchMedia,
19
+ });
20
+ class IntersectionObserver {
21
+ observe() {
22
+ // do nothing
23
+ }
24
+ unobserve() {
25
+ // do nothing
26
+ }
27
+ disconnect() {
28
+ // do nothing
29
+ }
30
+ }
31
+ Object.defineProperty(window, 'IntersectionObserver', {
32
+ writable: true,
33
+ value: IntersectionObserver,
34
+ });
35
+ class ResizeObserver {
36
+ observe() {
37
+ // do nothing
38
+ }
39
+ unobserve() {
40
+ // do nothing
41
+ }
42
+ disconnect() {
43
+ // do nothing
44
+ }
45
+ }
46
+ Object.defineProperty(window, 'ResizeObserver', {
47
+ writable: true,
48
+ value: ResizeObserver,
49
+ });
50
+ class MutationObserver {
51
+ observe() {
52
+ // do nothing
53
+ }
54
+ disconnect() {
55
+ // do nothing
56
+ }
57
+ }
58
+ Object.defineProperty(window, 'MutationObserver', {
59
+ writable: true,
60
+ value: MutationObserver,
61
+ });
package/start.js CHANGED
@@ -1,83 +1,68 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var fs_1 = require("fs");
5
- var path_1 = tslib_1.__importDefault(require("path"));
6
- var esbuild_1 = tslib_1.__importDefault(require("esbuild"));
7
- var esbuild_sass_plugin_1 = require("esbuild-sass-plugin");
8
- var yargs_1 = tslib_1.__importDefault(require("yargs"));
9
- var helpers_1 = require("yargs/helpers");
10
- (function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
11
- var _a, entry, outDir, context;
12
- return tslib_1.__generator(this, function (_b) {
13
- switch (_b.label) {
14
- case 0: return [4 /*yield*/, (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
15
- .options({
16
- entry: { type: 'string', default: 'src/__devonly__/index.tsx' },
17
- outDir: { type: 'string', default: 'dist' },
18
- })
19
- .parse()];
20
- case 1:
21
- _a = _b.sent(), entry = _a.entry, outDir = _a.outDir;
22
- if (!(0, fs_1.existsSync)(outDir)) {
23
- (0, fs_1.mkdirSync)(outDir);
24
- }
25
- (0, fs_1.copyFileSync)(__dirname + '/index.html', outDir + '/index.html');
26
- return [4 /*yield*/, esbuild_1.default.context({
27
- logLevel: 'debug',
28
- entryPoints: [entry],
29
- outdir: outDir,
30
- bundle: true,
31
- define: {
32
- global: 'window',
33
- },
34
- loader: {
35
- '.svg': 'dataurl',
36
- '.woff': 'dataurl',
37
- '.woff2': 'dataurl',
38
- },
39
- plugins: [
40
- (0, esbuild_sass_plugin_1.sassPlugin)({
41
- filter: /.module.(s[ac]ss|css)$/,
42
- type: 'css',
43
- transform: (0, esbuild_sass_plugin_1.postcssModules)({
44
- // ...put here the options for postcss-modules: https://github.com/madyankin/postcss-modules
45
- }),
46
- importMapper: function (path) { return (path.endsWith('styles.module') ? path + '.scss' : path); },
47
- precompile: function (source, pathname) {
48
- var basedir = path_1.default.dirname(pathname);
49
- return source.replace(/(url\(['"]?)(\.\.?\/)([^'")]+['"]?\))/g, '$1'.concat(basedir.replace(/\\/g, '\\\\'), '/$2$3'));
50
- },
51
- }),
52
- (0, esbuild_sass_plugin_1.sassPlugin)({
53
- filter: /.(s[ac]ss|css)$/,
54
- type: 'style',
55
- }),
56
- {
57
- name: 'resolve-fonts',
58
- setup: function (build) {
59
- build.onResolve({ filter: /\.woff2?$/ }, function (_a) {
60
- var path = _a.path;
61
- return { path: path };
62
- });
63
- },
64
- },
65
- ],
66
- })];
67
- case 2:
68
- context = _b.sent();
69
- return [4 /*yield*/, context.watch()];
70
- case 3:
71
- _b.sent();
72
- return [4 /*yield*/, context.serve({
73
- port: 3000,
74
- host: 'localhost',
75
- servedir: outDir,
76
- fallback: outDir + '/index.html',
77
- })];
78
- case 4:
79
- _b.sent();
80
- return [2 /*return*/];
81
- }
1
+ import { existsSync, mkdirSync, copyFileSync } from 'fs';
2
+ import path from 'path';
3
+ import url from 'url';
4
+ import esbuild from 'esbuild';
5
+ import { sassPlugin, postcssModules } from 'esbuild-sass-plugin';
6
+ import yargs from 'yargs';
7
+ import { hideBin } from 'yargs/helpers';
8
+ const __filename = url.fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ (async () => {
11
+ const { entry, outDir } = await yargs(hideBin(process.argv))
12
+ .options({
13
+ entry: { type: 'string', default: 'src/__devonly__/index.tsx' },
14
+ outDir: { type: 'string', default: 'dist' },
15
+ })
16
+ .parse();
17
+ if (!existsSync(outDir)) {
18
+ mkdirSync(outDir);
19
+ }
20
+ copyFileSync(__dirname + '/index.html', outDir + '/index.html');
21
+ const context = await esbuild.context({
22
+ logLevel: 'debug',
23
+ entryPoints: [entry],
24
+ outdir: outDir,
25
+ bundle: true,
26
+ define: {
27
+ global: 'window',
28
+ },
29
+ loader: {
30
+ '.svg': 'dataurl',
31
+ '.woff': 'dataurl',
32
+ '.woff2': 'dataurl',
33
+ },
34
+ plugins: [
35
+ sassPlugin({
36
+ filter: /.module.(s[ac]ss|css)$/,
37
+ type: 'css',
38
+ transform: postcssModules({
39
+ // ...put here the options for postcss-modules: https://github.com/madyankin/postcss-modules
40
+ }),
41
+ importMapper: path => (path.endsWith('styles.module') ? path + '.scss' : path),
42
+ precompile(source, pathname) {
43
+ const basedir = path.dirname(pathname);
44
+ return source.replace(/(url\(['"]?)(\.\.?\/)([^'")]+['"]?\))/g, '$1'.concat(basedir.replace(/\\/g, '\\\\'), '/$2$3'));
45
+ },
46
+ }),
47
+ sassPlugin({
48
+ filter: /.(s[ac]ss|css)$/,
49
+ type: 'style',
50
+ }),
51
+ {
52
+ name: 'resolve-fonts',
53
+ setup(build) {
54
+ build.onResolve({ filter: /\.woff2?$/ }, ({ path }) => {
55
+ return { path };
56
+ });
57
+ },
58
+ },
59
+ ],
82
60
  });
83
- }); })();
61
+ await context.watch();
62
+ await context.serve({
63
+ port: 3000,
64
+ host: 'localhost',
65
+ servedir: outDir,
66
+ fallback: outDir + '/index.html',
67
+ });
68
+ })();
package/test.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- declare const jestInstance: any;
2
- declare const argv: string[];
1
+ export {};
3
2
  //# sourceMappingURL=test.d.ts.map
package/test.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAM,YAAY,KAAkB,CAAC;AACrC,QAAA,MAAM,IAAI,UAAwB,CAAC"}
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":""}
package/test.js CHANGED
@@ -1,18 +1,18 @@
1
- 'use strict';
2
- var _a;
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
3
  // Do this as the first thing so that any code reading it knows the right env.
4
4
  process.env.BABEL_ENV = 'test';
5
5
  process.env.NODE_ENV = 'test';
6
6
  process.env.PUBLIC_URL = '';
7
- process.env.TZ = (_a = process.env.TZ) !== null && _a !== void 0 ? _a : 'Europe/Oslo';
7
+ process.env.TZ = process.env.TZ ?? 'Europe/Oslo';
8
8
  // Makes the script crash on unhandled rejections instead of silently
9
9
  // ignoring them. In the future, promise rejections that are not handled will
10
10
  // terminate the Node.js process with a non-zero exit code.
11
- process.on('unhandledRejection', function (err) {
11
+ process.on('unhandledRejection', err => {
12
12
  throw err;
13
13
  });
14
- var jestInstance = require('jest');
15
- var argv = process.argv.slice(2);
14
+ const jestInstance = require('jest');
15
+ const argv = process.argv.slice(2);
16
16
  // Always set config
17
17
  argv.push('--coverage');
18
18
  argv.push('--verbose');
@@ -0,0 +1,5 @@
1
+ import { UserConfigFn } from 'vitest/config';
2
+ export declare const getConfig: UserConfigFn;
3
+ declare const _default: import("vitest/config").UserConfigExport;
4
+ export default _default;
5
+ //# sourceMappingURL=vitest.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest.config.d.ts","sourceRoot":"","sources":["../src/vitest.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,eAAe,CAAC;AAE3D,eAAO,MAAM,SAAS,EAAE,YAgCvB,CAAC;;AAEF,wBAAmD"}
@@ -0,0 +1,35 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ export const getConfig = () => {
3
+ return {
4
+ test: {
5
+ include: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
6
+ globals: true,
7
+ environment: 'jsdom',
8
+ environmentOptions: {
9
+ jsdom: {
10
+ url: 'http://tjenester.helsenorge.utvikling',
11
+ },
12
+ },
13
+ setupFiles: ['node_modules/@helsenorge/library-build/setupTests.vite'],
14
+ css: {
15
+ modules: {
16
+ classNameStrategy: 'non-scoped',
17
+ },
18
+ },
19
+ coverage: {
20
+ enabled: true,
21
+ reporter: ['cobertura', 'lcov', 'json'],
22
+ },
23
+ reporters: ['default', 'junit'],
24
+ outputFile: {
25
+ junit: 'test-report.xml',
26
+ },
27
+ server: {
28
+ deps: {
29
+ inline: ['@helsenorge/designsystem-react', '@portabletext/react'],
30
+ },
31
+ },
32
+ },
33
+ };
34
+ };
35
+ export default defineConfig(env => getConfig(env));
@@ -1,27 +0,0 @@
1
- const browserslistFromPackageJson = require('./../package.json').browserslist;
2
-
3
- const parentBabelConfig = {
4
- presets: [
5
- [
6
- '@babel/preset-env',
7
- {
8
- targets: {
9
- node: 'current',
10
- browsers: browserslistFromPackageJson,
11
- },
12
- useBuiltIns: 'usage',
13
- corejs: 3,
14
- loose: true,
15
- },
16
- ],
17
- ['@babel/preset-react', { typescript: true }],
18
- ['@babel/preset-typescript', { allExtensions: true, isTSX: true }],
19
- ],
20
- plugins: [
21
- '@babel/plugin-syntax-dynamic-import',
22
- ['@babel/plugin-proposal-class-properties', { loose: true }],
23
- '@babel/plugin-transform-object-rest-spread',
24
- ],
25
- };
26
-
27
- module.exports = parentBabelConfig;