I'm trying to archive an entire folder using Node, archiver and fs, but nothing seems to happen.
This is my implementation:
import { createWriteStream } from 'fs';
import archiver from 'archiver';
await zipDirectory('./work', './work/folderName.zip');
const zipDirectory = async (source: string, out: string): Promise<void> => {
const archive = archiver('zip', { zlib: { level: 9 }});
return new Promise((resolve, reject) => {
const stream = createWriteStream(out);
archive
.directory(source, false)
.on('error', err => reject(err))
.pipe(stream);
stream.on('close', () => resolve());
archive.finalize();
});
}
Running on Node 14.15.4
Package.json
{
"name": "rpj",
"version": "1.0.0",
"description": "",
"main": "./dist/src/main.js",
"author": "David Faizulaev",
"license": "ISC",
"scripts": {
"start": "node ./dist/main.js",
"build": "yarn build:js",
"build:prod": "yarn run build:js",
"build:types": "tsc --emitDeclarationOnly",
"build:js": "babel . --out-dir ./dist --extensions \".ts\" --ignore node_modules --ignore dist --source-maps",
"build-ts": "tsc",
"test": "jest --coverage --verbose",
"lint-test": "npm run lint && npm run test",
"lint": "eslint -c .eslintrc.js --ext .ts ./src",
"lint:fix": "eslint --fix -c .eslintrc.js --ext .ts ./src",
"tslint": "tslint -c tslint.json --project tsconfig.json",
"sonar": "node ./config/sonar-project.js",
"prettier": "prettier --write ./projects/**/*.*",
"sonar-dev": "node ./config/sonar-dev-project.js"
},
"dependencies": {
"archiver": "^5.3.0",
"aws-sdk": "2.861.0",
"cheerio": "^1.0.0-rc.5",
"config": "3.3.6",
"esm": "^3.2.25",
"express": "^4.17.1",
"imagemin": "7.0.1",
"imagemin-mozjpeg": "^9.0.0",
"imagemin-pngquant": "^9.0.2",
"jszip": "3.6.0",
"lodash": "4.17.21",
"node-request-context": "^1.0.5",
"uuid": "^8.3.2",
"winston": "^3.3.3"
},
"devDependencies": {
"#babel/cli": "7.13.10",
"#babel/core": "7.13.10",
"#babel/plugin-proposal-class-properties": "7.13.0",
"#babel/plugin-proposal-object-rest-spread": "7.13.8",
"#babel/plugin-transform-runtime": "7.13.10",
"#babel/preset-env": "7.13.10",
"#babel/preset-typescript": "7.13.0",
"#babel/runtime": "7.13.10",
"#types/archiver": "^5.1.1",
"#types/config": "0.0.38",
"#types/express": "^4.17.11",
"#types/imagemin": "7.0.1",
"#types/imagemin-mozjpeg": "^8.0.1",
"#types/jest": "^26.0.20",
"#types/node": "14.14.33",
"#types/uuid": "^8.3.0",
"#typescript-eslint/eslint-plugin": "4.17.0",
"#typescript-eslint/eslint-plugin-tslint": "4.17.0",
"#typescript-eslint/parser": "4.17.0",
"aws-sdk-mock": "5.1.0",
"eslint": "7.21.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-jest": "^23.18.0",
"eslint-plugin-jsdoc": "32.2.0",
"jest": "27",
"lint-staged": "^10.5.3",
"sonarqube-scanner": "^2.8.0",
"ts-jest": "27",
"ts-node": "10",
"tslint": "^6.1.3",
"typescript": "4.4.4"
}
}
Please advise on how I can resolve this?
Issue was caused because I did not create the directory to where I wanted to store the zip file.
Once I added the directory creation at startup everything worked.
Related
I am creating a dependancy to generate PDF on nestjs, to do it I am using puppeteer.
When I try to use puppeteer inside the dependancy I get an error:
Error: Run `npm install` to download the correct Chromium revision (1056772).
But when I do it from the project and not the dependancy there is no error. It only happen when I use puppeteer from the dependancy, but it's launched from the same project.
First I generated the PDF inside a nestjs project and it worked fine.
Then I moved the code to my library inside a service but then there is the error.
I tried to run the following command to install chromium
node node_modules/puppeteer/install.js
But nothing change and here is the result of the command:
Chromium is already in C:\Users\Greg.cache\puppeteer\chrome\win64-1069273; skipping download.
I also tried to delete the node modules and reinstall it but no change.
The package.json of the dependancy:
{
"name": "#gboutte/nestjs-pdf",
"version": "0.0.3",
"description": "This package provide a service to render PDF from html string or from handlebars tempaltes for nestjs.",
"keywords": [
"nestjs",
"handlebars",
"hbs",
"templates",
"pdf"
],
"homepage": "https://github.com/gboutte/nestjs-pdf#readme",
"bugs": {
"url": "https://github.com/gboutte/nestjs-pdf/issues",
"email": "gboutte#protonmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/gboutte/nestjs-pdf"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rimraf dist && tsc",
"prepublish": "npm run build"
},
"author": "Grégory Boutte <gboutte#protonmail.com>",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"#nestjs/common": "^9.1.6",
"#gboutte/nestjs-hbs": "^0.0.3",
"#types/node": "^18.11.5",
"puppeteer": "^19.1.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.7",
"typescript": "^4.8.4"
},
"peerDependencies": {
"#nestjs/common": "^9.1.6",
"#gboutte/nestjs-hbs": "^0.0.3",
"#types/node": "^18.11.5",
"puppeteer": "^19.1.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.7",
"typescript": "^4.8.4"
}
}
And the package.json of the main project
{
"name": "nestjs-hbs-demo",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"main": "dist/index.js",
"readmeFilename": "README.md",
"files": [
"dist/**/*",
"*.md"
],
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"#gboutte/nestjs-hbs": "file:../nestjs-hbs",
"#gboutte/nestjs-pdf": "file:../nestjs-pdf",
"#nestjs/common": "^9.0.0",
"#nestjs/core": "^9.0.0",
"#nestjs/platform-express": "^9.0.0",
"#nestjs/platform-fastify": "^9.1.6",
"puppeteer": "^19.4.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
},
"devDependencies": {
"#nestjs/cli": "^9.0.0",
"#nestjs/schematics": "^9.0.0",
"#nestjs/testing": "^9.0.0",
"#types/express": "^4.17.13",
"#types/jest": "28.1.8",
"#types/node": "^16.0.0",
"#types/supertest": "^2.0.11",
"#typescript-eslint/eslint-plugin": "^5.0.0",
"#typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "28.1.3",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
I resolved the issue by updating my local nodejs and I changed the #types/node dependency of both project to be the same.
"#types/node": "^18.0.0",
I found out that it was this problem by trying to install the library with github instead of locally.
Before I used npm install ../directory-to-my-lib, then I used npm install <url to the github repo>.
The difference is that using github npm gave me an error saying that both version of #types/node were different, I don't know why I did not have this error using the other command.
Now that I fixed the version it works with all installation methods (npm package / github / locally).
I currently have 2 packages in my monorepo
web-ui & testing-utils
testing-utils
package.json
{
"name": "#testing-utils",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"lint": "eslint",
"postinstall": "cd ../../ && patch-package",
"test": "jest --passWithNoTests",
"prettier": "prettier ../../.prettierrc.js -c \"./**/*.{ts,tsx,js,jsx}\"",
"prettier:write": "prettier ../../.prettierrc.js --write \"./**/*.{ts,tsx,js,jsx}\""
},
"dependencies": {
"react": "16.14.0",
"react-redux": "7.2.2",
"redux": "4.0.5"
},
"devDependencies": {
"#babel/cli": "^7.2.3",
"#babel/core": "^7.12.10",
"#babel/plugin-proposal-class-properties": "^7.12.1",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/plugin-syntax-jsx": "^7.18.6",
"#babel/plugin-transform-react-jsx": "^7.19.0",
"#babel/plugin-transform-runtime": "^7.12.10",
"#babel/preset-env": "^7.19.4",
"#babel/preset-react": "^7.18.6",
"#babel/preset-typescript": "^7.18.6",
"#testing-library/react": "12.0.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",
"babel-loader": "^8.0.5",
"babel-plugin-react-require": "^3.1.3",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-preset-minify": "^0.6.0-alpha.9",
"eslint": "7.21.0",
"eslint-config-airbnb": "18.2.1",
"eslint-config-airbnb-typescript": "12.3.1",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.22.0",
"eslint-plugin-react-hooks": "4.2.0",
"prettier": "2.3.0",
"react-test-renderer": "16.14.0"
}
}
.babelrc
{
"presets": [["#babel/preset-env"], "#babel/preset-react"],
"ignore": ["node_modules/**"],
"plugins": ["#babel/plugin-transform-runtime", "#babel/plugin-syntax-jsx"]
}
renderWithTheme.js
import { render } from '#testing-library/react';
import { THEME } from '#web-ui/src/theme';
import React from 'react';
import { ThemeProvider } from 'styled-components';
const renderWithTheme = (ui) => {
function Wrapper({ children }) {
return <ThemeProvider theme={THEME}>{children}</ThemeProvider>;
}
return render(ui, { wrapper: Wrapper });
};
export default renderWithTheme;
web-ui
package.json
{
"name": "#web-ui",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
"jest": "jest",
"test": "jest --coverage --runInBand",
"typecheck": "npx tsc --noemit",
"prettier": "prettier ../../.prettierrc.js -c \"./src/**/*.{ts,tsx,js,jsx}\"",
"prettier:write": "prettier ../../.prettierrc.js --write \"./src/**/*.{ts,tsx,js,jsx}\""
},
"devDependencies": {
"#babel/plugin-syntax-jsx": "^7.18.6",
"#babel/plugin-transform-react-jsx": "^7.19.0",
"#babel/preset-env": "^7.19.4",
"#babel/preset-react": "^7.18.6",
"#testing-library/jest-dom": "^5.11.6",
"#testing-library/react": "12.0.0",
"#types/react": "16.14.0",
"babel-plugin-syntax-jsx": "^6.18.0",
"es-check": "^5.1.2",
"eslint": "7.21.0",
"eslint-config-airbnb": "18.2.1",
"eslint-config-airbnb-typescript": "12.3.1",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.22.0",
"eslint-plugin-react-hooks": "4.2.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^26.0.1",
"prettier": "2.3.0",
"react-test-renderer": "^16.13.1",
"typescript": "4.3.5"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.32",
"#fortawesome/free-brands-svg-icons": "^5.15.1",
"#fortawesome/free-regular-svg-icons": "^5.15.2",
"#fortawesome/pro-light-svg-icons": "^5.15.2",
"#fortawesome/pro-regular-svg-icons": "^5.15.1",
"#fortawesome/pro-solid-svg-icons": "^5.15.1",
"#fortawesome/react-fontawesome": "^0.1.13",
"#googlemaps/markerclustererplus": "^1.2.0",
"#juggle/resize-observer": "^3.3.1",
"#uiw/react-textarea-code-editor": "^2.0.3",
"axios": "^0.21.0",
"date-fns": "^1.9.0",
"dinero.js": "^1.6.0",
"formik": "^2.1.4",
"google-libphonenumber": "^3.2.15",
"libphonenumber": "0.0.10",
"lodash": "^4.17.20",
"moment": "^2.29.1",
"rc-slider": "^8.6.7",
"react-dates": "^21.8.0",
"react-number-format": "^4.4.1",
"react-router-dom": "^5.2.0",
"react-select": "^3.0.8",
"react-spinkit": "^3.0.0",
"react-spinners": "^0.10.6",
"react-spring": "^8.0.27",
"react-table": "^7.6.3",
"react-tag-autocomplete": "^6.1.0",
"react-transition-group": "^4.4.1",
"styled-components": "^4.4.1",
"use-resize-observer": "^7.0.0",
"yup": "^0.29.3"
},
"resolutions": {
"#types/react": "16.14.0"
}
}
.babelrc
{
"presets": [["#babel/preset-env"], "#babel/preset-react"],
"ignore": ["node_modules/**"],
"plugins": ["#babel/plugin-transform-runtime", "#babel/plugin-syntax-jsx"]
}
tests/form/form.test.js
import renderWithTheme from '#testing-utils/renderWithTheme';
import React, { useRef, useEffect } from 'react';
import { waitFor } from '#testing-library/react';
import Form from '../../src/form/Form/Form';
const FormDummy = (props) => {
const formRef = useRef();
const initialValues = {
terms: '',
};
useEffect(() => {
if (formRef && formRef.current) formRef.current.submitForm();
}, [formRef]);
return (
<div>
<Form onSubmit={props.onSub} formRef={formRef} initialValues={initialValues} />
</div>
);
};
describe('form', () => {
test('it should render without error', () => {
const initialValues = {
terms: '',
};
const { container } = renderWithTheme(<Form initialValues={initialValues} />);
expect(container).toBeDefined();
});
test('it should render without error when custom handle submit', async () => {
const onSub = jest.fn();
renderWithTheme(<FormDummy onSub={onSub} />);
await waitFor(() => expect(onSub).toBeCalled());
});
});
On the root of the monorepo I also have the following;
babel.config.js
module.exports = {
"presets": [["#babel/preset-env"], "#babel/preset-react"],
"ignore": ["node_modules/**"],
"plugins": ["#babel/plugin-transform-runtime", "#babel/plugin-syntax-jsx"]
}
package.json
{
"private": true,
"name": "monorepo",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"re-install": "rm -rf node_modules packages/node_modules packages/web-ui/node_modules packages/testing-utils/node_modules && yarn",
"lint": "yarn workspaces run lint",
"test": "yarn workspaces run test",
"typecheck": "yarn workspaces run tsc --noemit",
"prettier": "yarn workspaces run prettier",
"prettier:write": "yarn workspaces run prettier:write",
"postinstall": "patch-package",
"prepare": "husky install",
},
"devDependencies": {
"husky": "^6.0.0",
"minimist": "^1.2.5",
"patch-package": "^6.4.4",
"plist": "^3.0.1",
"postinstall-postinstall": "^2.1.0"
},
"workspaces": {
"packages": [
"packages/*"
]
},
"dependencies": {},
"resolutions": {
"#types/react": "16.14.0"
}
}
when trying to run npx jest form I get the following error;
FAIL __tests__/form/form.test.js
● Test suite failed to run
SyntaxError: ~~~/packages/testing-utils/renderWithTheme.js: Support for the experimental syntax 'jsx' isn't currently enabled (8:12):
6 | const renderWithTheme = (ui) => {
7 | function Wrapper({ children }) {
> 8 | return <ThemeProvider theme={THEME}>{children}</ThemeProvider>;
| ^
9 | }
10 |
11 | return render(ui, { wrapper: Wrapper });
Add #babel/preset-react (https://github.com/babel/babel/tree/main/packages/babel-preset-react) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add #babel/plugin-syntax-jsx (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-jsx) to the 'plugins' section to enable parsing.
As you can see from my files above, I have done the suggestion of adding #babel/preset-react to the presets section and added #babel/plugin-syntax-jsx to the plugins section to all my babel configs.
Where am I going wrong here?
Any help would be greatly appreciated.
What ended up actually working for me in the end was changing all the .babelrc files to be babel.config.js instead.
Not fully sure why that worked, but it did.
I'm following the NestJS documentation on how to set up a fastify/apollo server with nest but after adding fastify to main.ts I get this error:
FastifyError: fastify-plugin: fastify-accepts - expected '3.x' fastify version, '4.6.0' is installed
I've tried installing fastify 3.x, changing versions of other modules but according to yarn.lock some modules need 3.x and others need 4.x.
These are the docs I'm following:
https://docs.nestjs.com/techniques/performance
https://docs.nestjs.com/graphql/quick-start
Here is my main.ts
import { NestFactory } from '#nestjs/core';
import { AppModule } from './app.module';
import {
FastifyAdapter,
NestFastifyApplication,
} from '#nestjs/platform-fastify';
import { ValidationPipe } from '#nestjs/common';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({ logger: true }),
);
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();
Here is my package.json
{
"name": "app",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"#nestjs/apollo": "^10.1.0",
"#nestjs/common": "^9.0.0",
"#nestjs/core": "^9.0.0",
"#nestjs/graphql": "^10.1.2",
"#nestjs/platform-express": "^9.0.0",
"#nestjs/platform-fastify": "^9.1.1",
"apollo-server-fastify": "^3.10.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"firebase-admin": "^11.0.1",
"graphql": "^16.6.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"ts-morph": "^16.0.0"
},
"devDependencies": {
"#nestjs/cli": "^9.0.0",
"#nestjs/schematics": "^9.0.0",
"#nestjs/testing": "^9.0.0",
"#types/express": "^4.17.13",
"#types/jest": "28.1.8",
"#types/node": "^16.0.0",
"#types/supertest": "^2.0.11",
"#typescript-eslint/eslint-plugin": "^5.0.0",
"#typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "28.1.3",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
#nestjs/common#^9 and #nestjs/platform-fastify#^9 require you to use fastify#^4. However, apllo-server-fastify does not support fastify#^4 and will not until apollo-server v4 comes out. Until then,. you can follow the docs and use mercurius instead.
Your other option would be to downgrade to #nestjs/common#^8 and #nestjs/platform-fastify#^8 along with #nestjs/graphql#^9 which supports fastify#^3
I have the following code in main.ts file
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
console.log("working");
await app.listen(3000);
}
bootstrap();
when I run my application it runs successfully, but I am unable to access my controller's endpoints. I do not even see the working from console logs on my screen. It was running fine, but then stopped working after a while. I believe it could be due to some library I have added.
Just in case if it matters, below is my package.json
{
"name": "sfsf",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "npm run start:dev",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": "ts-node-dev ./node_modules/typeorm/cli.js"
},
"dependencies": {
"#nestjs/common": "^7.0.0",
"#nestjs/core": "^7.0.0",
"#nestjs/jwt": "^8.0.0",
"#nestjs/passport": "^8.0.1",
"#nestjs/platform-express": "^7.0.0",
"#nestjs/typeorm": "^8.0.2",
"bcryptjs": "^2.4.3",
"class-validator": "^0.13.2",
"dotenv": "^10.0.0",
"module": "^1.2.5",
"mysql2": "^2.3.3",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.4.0",
"typeorm": "^0.2.41"
},
"devDependencies": {
"#nestjs/cli": "^7.0.0",
"#nestjs/schematics": "^7.0.0",
"#nestjs/testing": "^7.0.0",
"#types/express": "^4.17.3",
"#types/jest": "26.0.10",
"#types/node": "^13.9.1",
"#types/passport-jwt": "^3.0.6",
"#types/passport-local": "^1.0.34",
"#types/supertest": "^2.0.8",
"#typescript-eslint/eslint-plugin": "3.9.1",
"#typescript-eslint/parser": "3.9.1",
"eslint": "7.7.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"jest": "26.4.2",
"prettier": "^1.19.1",
"supertest": "^4.0.2",
"ts-jest": "26.2.0",
"ts-loader": "^6.2.1",
"ts-node": "9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
Upgrade every #nestjs/* package to v8. Or downgrade them to v7 and rxjs to v6
Below I have a sample test for a Typescript project. I'm using mocha chai to do the testing. The test case is blank for now.
import {KafkaConsumer} from '../infrastructure/delivery/kafka/kafka-consumer';
import {expect} from 'chai';
import {describe, it} from 'mocha';
describe('KafkaConsumer Initialization', () => {
it('should initialize KafkaConsumer', () => {
})
})
When I run the test I get the following error:
import {describe} from 'mocha';
^
SyntaxError: Unexpected token {
Any idea why this might be? If I change line 3 to import 'mocha'; I a similar SyntaxError. Without that line, describe() and it() are not defined
Below is my package.json file.
{
"name": "wss",
"version": "0.0.0",
"private": true,
"main": "dist/index.js",
"scripts": {
"tsc": "tsc",
"start": "node --inspect=5858 -r ts-node/register ./src/index.ts",
"start:watch": "nodemon",
"build": "tsc",
"prod": "tsc && npm run postbuild && node ./dist/index.js",
"postbuild": "npm run copy-files",
"copy-files": "copyfiles -u 1 ./src/**/*.js dist",
"test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'tests/**/*.ts'",
"test:watch": "nodemon --exec npm test"
},
"nyc": {
"require": [
"ts-node/register"
],
"include": [
"src/**/*.ts"
],
"extension": [
".ts"
],
"reporter": [
"lcov",
"text"
],
"sourceMap": true,
"instrument": true
},
"dependencies": {
"#types/dotenv": "^6.1.1",
"#types/newrelic": "^5.11.0",
"#types/redis": "^2.8.21",
"aws-iot-device-sdk": "^2.2.4",
"axios": "^0.19.0",
"bluebird": "^3.5.5",
"chai-http": "^4.3.0",
"cookie-parser": "~1.4.3",
"copyfiles": "^2.2.0",
"dotenv": "^7.0.0",
"express": "~4.16.0",
"kafka-node": "^4.1.3",
"lodash": "^4.17.15",
"morgan": "~1.9.0",
"newrelic": "^5.11.0",
"redis": "^3.0.2",
"reflect-metadata": "^0.1.13",
"uuid": "^8.0.0"
},
"devDependencies": {
"#types/bluebird": "^3.5.27",
"#types/express": "^4.16.1",
"#types/jsonwebtoken": "^8.3.2",
"#types/lodash": "^4.14.150",
"#types/mocha": "^8.0.0",
"#types/node": "^11.13.14",
"#types/winston": "^2.4.4",
"chai": "^4.2.0",
"eslint": "^4.19.1",
"mocha": "^8.0.1",
"nodemon": "^1.18.11",
"nyc": "^14.1.1",
"ts-node": "^8.10.2",
"ts-node-dev": "^1.0.0-pre.41",
"tslint": "^5.16.0",
"typescript": "^3.9.2",
"typescript-eslint-parser": "^22.0.0"
}
}
RESOLVED! test script in package.json should be changed to:
"test": "mocha --require ts-node/register --watch-extensions ts './src/test/test.ts'",