Problem with 'Robot Name' exercise

Hi everyone!

Disclaimer: I’m a complete newbie in JavaScript and programming, so please have patience with me.

I have problems running test for ‘Robot Name’ exercise in the JavaScript track. When I run tests in the web version of Exercism I get redeclaration of import beforeEach error, so I tried to install Exercism’s CLI version. Runnin test in the CLI version also produces an error:

 FAIL  ./robot-name.spec.js
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    SyntaxError: /home/mytia/exercism/javascript/robot-name/robot-name.js: Unexpected token (11:8)

       9 |   static existingNames = new Set();
      10 |
    > 11 |   static.releaseNames() {
         |         ^
      12 |     Robot.existingNames.clear();
      13 |   }
      14 |

       7 |   xtest,
       8 | } from '@jest/globals';
    >  9 | import { Robot } from './robot-name';
         | ^
      10 |
      11 | const areSequential = (name1, name2) => {
      12 |   const alpha1 = name1.substring(0, 2);

      at constructor (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parse-error.ts:95:45)
      at Parser.toParseError [as raise] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/tokenizer/index.ts:1507:19)
      at Parser.raise [as unexpected] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/tokenizer/index.ts:1547:16)
      at Parser.unexpected [as parsePropertyName] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/expression.ts:2451:18)
      at Parser.parsePropertyName [as parseClassElementName] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:2147:10)
      at Parser.parseClassElementName [as parseClassMemberWithIsStatic] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:1991:22)
      at Parser.parseClassMemberWithIsStatic [as parseClassMember] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:1938:10)
      at parseClassMember (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:1851:14)
      at Parser.callback [as withSmartMixTopicForbiddingContext] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/expression.ts:3176:14)
      at Parser.withSmartMixTopicForbiddingContext [as parseClassBody] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:1823:10)
      at Parser.parseClassBody [as parseClass] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:1774:22)
      at Parser.parseClass [as parseExportDeclaration] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:2628:25)
      at Parser.parseExportDeclaration [as maybeParseExportDeclaration] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:2551:31)
      at Parser.maybeParseExportDeclaration [as parseExport] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:2432:29)
      at Parser.parseExport [as parseStatementContent] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:649:25)
      at Parser.parseStatementContent [as parseStatementLike] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:482:17)
      at Parser.parseStatementLike [as parseModuleItem] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:419:17)
      at Parser.parseModuleItem [as parseBlockOrModuleBlockBody] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:1443:16)
      at Parser.parseBlockOrModuleBlockBody [as parseBlockBody] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:1417:10)
      at Parser.parseBlockBody [as parseProgram] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:229:10)
      at Parser.parseProgram [as parseTopLevel] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/statement.ts:203:25)
      at Parser.parseTopLevel [as parse] (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/parser/index.ts:88:25)
      at parse (node_modules/.pnpm/@babel+parser@7.28.5/node_modules/@babel/parser/src/index.ts:86:38)
      at parser (node_modules/.pnpm/@babel+core@7.28.5/node_modules/@babel/core/src/parser/index.ts:29:19)
          at parser.next (<anonymous>)
      at normalizeFile (node_modules/.pnpm/@babel+core@7.28.5/node_modules/@babel/core/src/transformation/normalize-file.ts:50:24)
          at normalizeFile.next (<anonymous>)
      at run (node_modules/.pnpm/@babel+core@7.28.5/node_modules/@babel/core/src/transformation/index.ts:41:36)
          at run.next (<anonymous>)
      at transform (node_modules/.pnpm/@babel+core@7.28.5/node_modules/@babel/core/src/transform.ts:29:20)
          at transform.next (<anonymous>)
      at evaluateSync (node_modules/.pnpm/gensync@1.0.0-beta.2/node_modules/gensync/index.js:251:28)
      at sync (node_modules/.pnpm/gensync@1.0.0-beta.2/node_modules/gensync/index.js:89:14)
      at fn (node_modules/.pnpm/@babel+core@7.28.5/node_modules/@babel/core/src/errors/rewrite-stack-trace.ts:99:14)
      at transformSync (node_modules/.pnpm/@babel+core@7.28.5/node_modules/@babel/core/src/transform.ts:66:52)
      at ScriptTransformer.transformSource (node_modules/.pnpm/@jest+transform@29.7.0/node_modules/@jest/transform/build/ScriptTransformer.js:545:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/.pnpm/@jest+transform@29.7.0/node_modules/@jest/transform/build/ScriptTransformer.js:674:40)
      at ScriptTransformer.transform (node_modules/.pnpm/@jest+transform@29.7.0/node_modules/@jest/transform/build/ScriptTransformer.js:726:19)
      at Object.require (robot-name.spec.js:9:1)

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

I will be honest, I have no idea what this error even means or how to proceed from here. I started with programming ~2 months ago, so this is a bit over my head…

Here is my code so far:

export class Robot {
  constructor() {
    this._name = this.randomName();
  }

  static existingNames = new Set();

  static.releaseNames() {
    Robot.existingNames.clear();
  }

  get name() {
    return this._name;
  }

  randomName() {
    let name = new Array();
    const alphabet = Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ');

    const randomLetter = () => alphabet[Math.floor(Math.random() * alphabet.length)];
    const randomNumber = () => Math.floor(Math.random() * 10);

    while (name.length < 6) name.push((name.length < 3) ? randomLetter() : randomNumber());
    name.join('');

    if (Robot.existingNames.has(name)) return this.randomName();

    Robot.existingNames.add(name);
    return name;
  }

  reset() {
    this._name = this.randomName();
  }
}

I would really appreciate any hint. :sweat_smile:

Remove the dot after static in line 8.

2 Likes

Oh, that’s embarrassing. I’ve been trying to find what I did wrong for hours and didn’t see this dot :sweat_smile: Thank you, @atk! Now the tests run, so I’ll be able to continue.

It happens to all of us! I did see it when you posted if in the other thread but it’s a typical thing I would miss as well.

Have fun with the next one.

1 Like