Skip to content

Commit

Permalink
additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
kormide committed Jan 30, 2024
1 parent 0fc0c67 commit fc6954c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 3 additions & 3 deletions e2e/__snapshots__/e2e.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ modules/unversioned/1.0.0/MODULE.bazel
----------------------------------------------------
module(
name = \\"unversioned\\",
version = \\"1.0.0\\"
version = \\"1.0.0\\",
)
----------------------------------------------------
Expand All @@ -183,7 +183,7 @@ modules/unversioned/1.0.0/patches/module_dot_bazel_version.patch
module(
- name = \\"unversioned\\"
+ name = \\"unversioned\\",
+ version = \\"1.0.0\\"
+ version = \\"1.0.0\\",
)
----------------------------------------------------
Expand All @@ -208,7 +208,7 @@ modules/unversioned/1.0.0/source.json
\\"strip_prefix\\": \\"unversioned-1.0.0\\",
\\"url\\": \\"https://github.com/testorg/unversioned/archive/refs/tags/v1.0.0.tar.gz\\",
\\"patches\\": {
\\"module_dot_bazel_version.patch\\": \\"sha256-CahdP4+xcGJVM9GyA0Sg2rUe5rIPHzKJ6J4SfFTm2x8=\\"
\\"module_dot_bazel_version.patch\\": \\"sha256-LGXyh9FLhgIPbe0gHfxAPnEQ7HVR+HUP/IDbPdl3ZkA=\\"
},
\\"patch_strip\\": 1
}
Expand Down
19 changes: 18 additions & 1 deletion src/domain/module-file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,24 @@ module(
expect(moduleFile.content).toEqual(`\
module(
name = "rules_foo",
version = "4.5.6"
version = "4.5.6",
)`);
});

test("stamps the version when the version field was originally missing and the last field is comma-trailed", () => {
mocked(fs.readFileSync).mockReturnValue(`\
module(
name = "rules_foo",
compatibility_level = 1,
)`);
const moduleFile = new ModuleFile("MODULE.bazel");
moduleFile.stampVersion("4.5.6");

expect(moduleFile.content).toEqual(`\
module(
name = "rules_foo",
compatibility_level = 1,
version = "4.5.6",
)`);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/domain/module-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class ModuleFile {
} else {
// add the version
this.moduleContent = this.moduleContent.replace(
/(^.*?module\(.*?)(\s*)\)/s,
`$1,\n version = "${version}"\n)`
/(^.*?module\(.*?),?(\s*)\)/s,
`$1,\n version = "${version}",\n)`
);
}
}
Expand Down

0 comments on commit fc6954c

Please sign in to comment.