0

I have some node (typescript) code which is slightly broken and produces an error when I run it (not my problem here).

When I run it in M-x shell mode, I get:

$ jest
FAIL src/db/DbLookups.test.ts
  ● Test suite failed to run

    src/db/DbLookups.ts:4:23 - error TS1003: Identifier expected.

    4   return db.query(sql.({ company_id: companyId }))
                            ~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.9 s
Ran all test suites.
$

which looks like this: enter image description here

When I do M-x compile and jest, I get this:

-*- mode: compilation; default-directory: "~/cogcred/api-text_search/" -*-
Compilation started at Mon Oct 23 20:34:04

jest
FAIL src/db/DbLookups.test.ts
  ● Test suite failed to run

    [96msrc/db/DbLookups.ts[0m:[93m4[0m:[93m23[0m - [91merror[0m[90m TS1003: [0mIdentifier expected.

    [7m4[0m   return db.query(sql.({ company_id: companyId }))
    [7m [0m [91m                      ~[0m

[999D[KTest Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        3.14 s
Ran all test suites.

Compilation exited abnormally with code 1 at Mon Oct 23 20:34:08

which looks like this: enter image description here

Some of the colouring is coming through and some is some is totally mangled. Any idea how I can either (a) make it work or (b) turn it off completely? And no --no-colours as an arg to jest doesn't work.

1 Answer 1

0

Compilation mode is not a terminal emulator. It is intended that programs that it runs have TERM=dumb, so that they know not to output any escape sequences. However, because the compile command is run in a shell, your shell init file could be accidentally setting TERM to something else. You can check for this by running M-x compile, then entering echo $TERM as the command. (Your shell init files should never set TERM at all; you should let your terminal emulator set it to the correct value instead.)

Alternatively, it could just be a bug in jest. Sadly some programs take the shortcut of just assuming that they are running in a terminal, and that the terminal will support the features that they want to use. If jest is one of these programs then you need to find a way to fix jest, perhaps by reading its documentation, or asking questions in their mailing list or support forum, or by patching jest yourself.

2
  • echo $TERM shows dumb. If there's no escape sequences how does any colouring work in compilation mode? Oct 24, 2023 at 10:44
  • 1
    compilation-mode does colorize a few things itself, such as the message at the bottom where it says “exited abnormally”, and it also applies regexes to find certain things in the text and colorize them, such as where it says “Tests:”. But jest shouldn’t print any escape sequences when TERM=dumb, since a dumb terminal won’t recognize them. I see also that it tried to move the cursor just before it printed the summary statistics, which I suppose is a good idea in a real terminal since the source code it prints could, in principle, have contained escape sequences that would mess up the alignment.
    – db48x
    Oct 24, 2023 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.