question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid Typescript File

See original GitHub issue

when i run ngentest app.component.ts, i get:

Error. invalid typescript file. e.g., Usage $0 <tsFile> [options]

my ngentest.config.js file:

const fs = require('fs');
const path = require('path');
const klassTemplate = fs.readFileSync(path.join(__dirname, 'src', 'class', 'class.template.ts.ejs'), 'utf8');
const componentTemplate = fs.readFileSync(path.join(__dirname, 'src', 'component', 'component.template.ts.ejs'), 'utf8');
const directiveTemplate = fs.readFileSync(path.join(__dirname, 'src', 'directive', 'directive.template.ts.ejs'), 'utf8');
const injectableTemplate = fs.readFileSync(path.join(__dirname, 'src', 'injectable', 'injectable.template.ts.ejs'), 'utf8');
const pipeTemplate = fs.readFileSync(path.join(__dirname, 'src', 'pipe', 'pipe.template.ts.ejs'), 'utf8');

module.exports = {
  framework: 'karma', // or 'jest'
  templates: {
    klass: klassTemplate,  // ejs contents read from file
    component: componentTemplate,
    directive: directiveTemplate,
    injectable: injectableTemplate,
    pipe: pipeTemplate
  },
  // necessary directives used for a component test
  directives: [
    'oneviewPermitted'
  ],
  // necessary pipes used for a component test
  pipes: [
    'translate', 'phoneNumber', 'safeHtml'
  ],
  // when convert to JS, some codes need to be replaced to work
  replacements: [ // some 3rd party module causes an error
    { from: 'require\\("html-custom-element"\\)', to: '{}'},
    { from: '^\\S+\\.define\\(.*\\);', to: ''} // some commands causes error
  ],
  // when constructor param type is as following, create a mock class with this properties
  // e.g. @Injectable() MockElementRef { nativeElement = {}; }
  providerMocks: {
    ElementRef: ['nativeElement = {};'],
    Router: ['navigate() {};'],
    Document: ['querySelector() {};'],
    HttpClient: ['post() {};'],
    TranslateService: ['translate() {};'],
    EncryptionService: [],
  },
  // when ngentest runs with a directory, include only these files
  includeMatch: [/(component|directive|pipe|service).ts/],
  // when ngentest runs with a directory, exclude these files
  excludeMatch: []
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mohamed-attiacommented, Jan 22, 2020

i was getting the same error and when i provide the full path it is work with me (i am using windows 10) or you can open the terminal with the current directory of the file you need to test and provide the command with the file name only (using vscode) => ngentest “filename”

0reactions
subratbholacommented, Dec 21, 2022

even i am getting the same issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting invalid typescript errors in valid TS code - Stack Overflow
I am having a create-react-app (v17.0.2) with typescript (v4.5.5). I am getting typescript errors even in valid TS code.
Read more >
ae-wrong-input-file-type - API Extractor
Unlike some other tools, API Extractor does not process TypeScript source files directly. Instead, it is designed to analyze the .d.ts files that...
Read more >
TypeScript errors and how to fix them
export function logSomething(error: unknown): void;. Alternatively, you can write your function implementation inside a source code file ( *.ts ). TS1192.
Read more >
Documentation - Do's and Don'ts - TypeScript
Recommendations for writing d.ts files. ... WRONG */. function reverse(s: String): String;. ✓ Do use the types number , string , boolean ,...
Read more >
Permanent warning "Your project contained an invalid value ...
Run npx typescript --init (or add a basic tsconfig.json file); Open the new project in Visual Studio; See the warning showing up in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found