Skip to content

Commit

Permalink
refactor(mmel): Make tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
ribose-jeffreylau committed Feb 17, 2023
1 parent b115f83 commit d116309
Show file tree
Hide file tree
Showing 18 changed files with 996 additions and 1,492 deletions.
6 changes: 0 additions & 6 deletions packages/legacy/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
},
"jsc": {
"externalHelpers": false,
"paths": {
"@paneron/*": [
"../*/src"
]
},
"baseUrl": ".",
"parser": {
"syntax": "typescript",
"tsx": true,
Expand Down
24 changes: 9 additions & 15 deletions packages/legacy/codecept.conf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// import { setHeadlessWhen, setCommonPlugins } from '@codeceptjs/configure';
const { setHeadlessWhen, setCommonPlugins } = require('@codeceptjs/configure');
const { bootstrap } = require('./codeceptjs_presettings.ts');
import { setHeadlessWhen, setCommonPlugins } from '@codeceptjs/configure';

/**
* Turn on headless mode when running with HEADLESS=true environment variable
Expand All @@ -14,26 +12,22 @@ setHeadlessWhen(process.env.HEADLESS);
*/
setCommonPlugins();

export const config = {
export const config: CodeceptJS.MainConfig = {
// tests : './*_test.ts',
// tests : '**/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x)',
tests : './e2e_tests/**/*_test.[tj]s?(x)',
// output : './output',
output : './test_outputs',
helpers : {
Playwright : {
url : './paneron/dist/main/main.js',
// url : 'http://localhost',
show : true,
browser : 'electron'
}
},
bootstrap,
include : {},
name : 'extension-hls',
plugins : {
retryFailedStep : {
enabled : true
},
screenshotOnFail : {
enabled : true
}
}
include : {
I : './steps_file'
},
name : 'legacy'
}
33 changes: 24 additions & 9 deletions packages/legacy/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
* https://jestjs.io/docs/configuration
*/

export default {
import { pathsToModuleNameMapper } from 'ts-jest';
import { compilerOptions } from './tsconfig.json';

import type { JestConfigWithTsJest } from 'ts-jest';

const jestConfig: JestConfigWithTsJest = {
// All imported modules in your tests should be mocked automatically
// automock: false,

Expand All @@ -30,9 +35,9 @@ export default {
coverageDirectory : 'coverage',

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
coveragePathIgnorePatterns : [
'/dist/'
],

// Indicates which provider should be used to instrument code for coverage
// coverageProvider: "babel",
Expand Down Expand Up @@ -103,10 +108,16 @@ export default {
// A map from regular expressions to module names or to arrays of module
// names that allow to stub out resources with a single module
// moduleNameMapper: {},
moduleNameMapper : pathsToModuleNameMapper(
compilerOptions.paths,
{ prefix : '<rootDir>/' },
),

// An array of regexp pattern strings, matched against all module paths
// before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
modulePathIgnorePatterns : [
'/dist/',
],

// Activates notifications for test results
// notify: false,
Expand Down Expand Up @@ -140,9 +151,11 @@ export default {
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],
roots : [
'<rootDir>'
],

modulePaths : [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",
Expand Down Expand Up @@ -203,7 +216,7 @@ export default {

// Use @swc/jest to support nodejs 14.x:
transform : {
'^.+\\.(t|j)sx?$' : ['@swc/jest'],
'^.+\\.(t|j)sx?$' : ['@swc/jest', {}],
},

// An array of regexp pattern strings that are matched against all source
Expand All @@ -227,3 +240,5 @@ export default {
// Whether to use watchman for file crawling
// watchman: true,
};

export default jestConfig;
26 changes: 14 additions & 12 deletions packages/legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"typecheck": "tsc -p tsconfig.build.json --noEmit",
"build:decl": "tsc -p tsconfig.build.json --emitDeclarationOnly",
"build": "run-script-os",
"build:default": "swc src --ignore '*.test.*' --out-dir ${npm_package_dist_dir} --copy-files --extensions '.ts,.tsx,.js,.jsx' && cp package.json ${npm_package_dist_dir}/",
"build:win32": "mkdirp %npm_package_dist_dir% && swc src --out-dir %npm_package_dist_dir% --copy-files --extensions '.ts,.tsx,.js,.jsx' && copy package.json %npm_package_dist_dir%",
"build:default": "swc src --sync --ignore '*.test.*' --out-dir ${npm_package_dist_dir} --copy-files --extensions '.ts,.tsx,.js,.jsx,.json' && cp package.json ${npm_package_dist_dir}/",
"build:win32": "mkdirp %npm_package_dist_dir% && swc src --sync --out-dir %npm_package_dist_dir% --copy-files --extensions '.ts,.tsx,.js,.jsx,.json' && copy package.json %npm_package_dist_dir%",
"inject": "run-script-os",
"inject:mac": "mkdirp $HOME/'Library/Application Support'/Paneron/plugins/${npm_package_name}; rsync -a ${npm_package_dist_dir}/ $HOME/'Library/Application Support'/Paneron/plugins/${npm_package_name}/",
"inject:win32": "mkdirp \"%appdata%\\Paneron\\plugins\\@paneron\\extension-hls\" && xcopy /e /y %npm_package_dist_dir% \"%appdata%\\Paneron\\plugins\\@paneron\\extension-hls\" > nul",
Expand Down Expand Up @@ -58,23 +58,24 @@
"@emotion/eslint-plugin": "^11.10.0",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@paneron/libmmel": "workspace:*",
"@react-three/drei": "^7.27.5",
"@react-three/fiber": "^7.0.29",
"@riboseinc/paneron-extension-glossarist": "1.0.0-dev9",
"@riboseinc/paneron-extension-kit": "^2.0.0-alpha24",
"@paneron/libmmel": "workspace:*",
"@swc/cli": "^0.1.57",
"@swc/core": "^1.3.14",
"@swc/jest": "^0.2.23",
"@swc/core": "^1.3.35",
"@swc/helpers": "^0.4.14",
"@swc/jest": "^0.2.24",
"@types/jest": "^29.2.2",
"@types/node": "18.11.9",
"@types/react": "16.14.30",
"@types/react-reconciler": "^0.28.0",
"@types/three": "^0.146.0",
"@types/webpack-env": "^1.18.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"codeceptjs": "^3.3.6",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"codeceptjs": "^3.4.1",
"concurrently": "^7.5.0",
"electron": "^21.2.3",
"electron-log": "^4.4.8",
Expand All @@ -86,22 +87,23 @@
"eslint-plugin-react-hooks": "^4.6.0",
"fast-check": "^3.3.0",
"immer": "^9.0.16",
"jest": "^29.3.1",
"jest": "^29.4.3",
"liquidjs": "^9.42.1",
"mkdirp": "^1.0.4",
"playwright": "^1.27.1",
"playwright": "^1.30.0",
"prop-types": "^15.8.1",
"react": "16.14.0",
"react-dom": "^16.14.0",
"react-flow-renderer": "^9.7.4",
"react-mathjax2": "^0.0.2",
"regenerator-runtime": "^0.13.11",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6",
"three": "^0.146.0",
"three-stdlib": "^2.17.3",
"ts-jest": "^29.0.3",
"ts-jest": "^29.0.5",
"ts-node": "10.9.1",
"typescript": "4.8.4"
"typescript": "4.9.5"
},
"license": "MIT"
}
4 changes: 2 additions & 2 deletions packages/legacy/src/smart/model/editor/commands/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function editImportRegistryCommand(
id: string,
value: RegistryCombined,
refs: MMELReference[]
) {
): ModelAction {
const action: ModelAction = {
type : 'model',
act : 'hybird',
Expand Down Expand Up @@ -135,7 +135,7 @@ export function editImportDCCommand(
id: string,
value: EditorDataClass,
refs: MMELReference[]
) {
): ModelAction {
const action: ModelAction = {
type : 'model',
act : 'hybird',
Expand Down
10 changes: 5 additions & 5 deletions packages/legacy/src/smart/model/editor/commands/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function editEGateCommand(
page: string,
update: EditorEGate,
edges: MMELEdge[]
) {
): ModelAction {
const action: ModelAction = {
type : 'model',
act : 'hybird',
Expand All @@ -65,7 +65,7 @@ export function editEGateCommand(
* Add a subprocess page to the process
* @param id The Process ID
*/
export function createSubprocessCommand(id: string) {
export function createSubprocessCommand(id: string): ModelAction {
const action: ModelAction = {
type : 'model',
act : 'hybird',
Expand All @@ -79,7 +79,7 @@ export function createSubprocessCommand(id: string) {
* Remove the subprocess page from the process
* @param id The Process ID
*/
export function deleteSubprocessCommand(id: string) {
export function deleteSubprocessCommand(id: string): ModelAction {
const action: ModelAction = {
type : 'model',
act : 'hybird',
Expand All @@ -94,7 +94,7 @@ export function deleteSubprocessCommand(id: string) {
* @param id The process ID
* @param page The page where the process is removed
*/
export function bringoutProcessCommand(id: string, page: string) {
export function bringoutProcessCommand(id: string, page: string): ModelAction {
const action: ModelAction = {
type : 'model',
act : 'hybird',
Expand All @@ -121,7 +121,7 @@ export function editProcessCommand(
notes: MMELNote[],
links: MMELLink[],
refs: MMELReference[]
) {
): ModelAction {
const newProcess: EditorProcess = {
...process,
provision : new Set(provisions.map(x => x.id)),
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/src/smart/model/editor/commands/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function importElmCommand(
x: number,
y: number,
page: string
) {
): ModelAction {
const action: ModelAction = {
type : 'model',
act : 'hybird',
Expand Down
10 changes: 5 additions & 5 deletions packages/legacy/src/smart/model/editor/commands/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ModelAction } from '../model';
* @param page The page ID
* @param id The edge ID
*/
export function removeEdgeCommand(page: string, id: string) {
export function removeEdgeCommand(page: string, id: string): ModelAction {
const action: ModelAction = {
type : 'model',
act : 'pages',
Expand All @@ -34,7 +34,7 @@ export function newEdgeCommand(
page: EditorSubprocess,
source: string,
target: string
) {
): ModelAction {
const newEdge = createEdge(findUniqueID('Edge', page.edges));
newEdge.from = source;
newEdge.to = target;
Expand All @@ -48,10 +48,10 @@ export function newEdgeCommand(
return action;
}

type DragStartRecord = {
interface DragStartRecord {
x: number;
y: number;
};
}

/**
* The element is moved on the page
Expand All @@ -65,7 +65,7 @@ export function dragCommand(
model: EditorModel,
flowNode: Node,
ds: DragStartRecord
) {
): ModelAction {
const action: ModelAction = {
type : 'model',
act : 'pages',
Expand Down
10 changes: 10 additions & 0 deletions packages/legacy/steps_file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// in this file you can append custom step methods to 'I' object

module.exports = function() {
return actor({

// Define custom steps here, use 'this' to access default methods of I.
// It is recommended to place a general 'login' function here.

});
}
11 changes: 11 additions & 0 deletions packages/legacy/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
"../../src/@types",
"./node_modules/@types"
],
"composite": true,
"module": "esnext",
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"paths": {
"@paneron/libmmel/*": ["./libmmel/src/*"]
}
},
"include": [
"**.json",
"*.ts",
"src"
],
"exclude": [
Expand All @@ -27,6 +34,10 @@
"node_modules"
],
"ts-node": {
"swc": true,
"compilerOptions": {
"module": "CommonJS"
},
"files": true
},
"references": [
Expand Down
Loading

0 comments on commit d116309

Please sign in to comment.