Repository: googlemaps/js-api-loader
Pull request #56 (2020-09-21 06:02:30)

build(deps-dev): bump eslint-plugin-jest from 24.0.0 to 24.0.2
Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 24.0.0 to 24.0.2.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/jest-community/eslint-plugin-jest/releases">eslint-plugin-jest's releases</a>.</em></p>
<blockquote>
<h2>v24.0.2</h2>
<h2><a href="https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.1...v24.0.2">24.0.2</a> (2020-09-20)</h2>
<h3>Bug Fixes</h3>
<ul>
<li><strong>no-if:</strong> check both types of function expression (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/672">#672</a>) (<a href="https://github.com/jest-community/eslint-plugin-jest/commit/d462d50aed84ad4dc536a1f47bb7af6abd3dbe92">d462d50</a>), closes <a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/670">#670</a></li>
</ul>
<h2>v24.0.1</h2>
<h2><a href="https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.0...v24.0.1">24.0.1</a> (2020-09-12)</h2>
<h3>Bug Fixes</h3>
<ul>
<li>don't include deprecated rules in <code>all</code> config (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/664">#664</a>) (<a href="https://github.com/jest-community/eslint-plugin-jest/commit/f636021c16215a713845c699858a2978211df49d">f636021</a>), closes <a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/663">#663</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/jest-community/eslint-plugin-jest/blob/master/CHANGELOG.md">eslint-plugin-jest's changelog</a>.</em></p>
<blockquote>
<h2><a href="https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.1...v24.0.2">24.0.2</a> (2020-09-20)</h2>
<h3>Bug Fixes</h3>
<ul>
<li><strong>no-if:</strong> check both types of function expression (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/672">#672</a>) (<a href="https://github.com/jest-community/eslint-plugin-jest/commit/d462d50aed84ad4dc536a1f47bb7af6abd3dbe92">d462d50</a>), closes <a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/670">#670</a></li>
</ul>
<h2><a href="https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.0...v24.0.1">24.0.1</a> (2020-09-12)</h2>
<h3>Bug Fixes</h3>
<ul>
<li>don't include deprecated rules in <code>all</code> config (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/664">#664</a>) (<a href="https://github.com/jest-community/eslint-plugin-jest/commit/f636021c16215a713845c699858a2978211df49d">f636021</a>), closes <a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/663">#663</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/jest-community/eslint-plugin-jest/commit/c8a040a8ae9f33269e4c4d00ef7c77ef8e092ec6"><code>c8a040a</code></a> chore(release): 24.0.2 [skip ci]</li>
<li><a href="https://github.com/jest-community/eslint-plugin-jest/commit/d462d50aed84ad4dc536a1f47bb7af6abd3dbe92"><code>d462d50</code></a> fix(no-if): check both types of function expression (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/672">#672</a>)</li>
<li><a href="https://github.com/jest-community/eslint-plugin-jest/commit/b4319e8ab2001d10af2aee542a07b4f0eb5dd4c3"><code>b4319e8</code></a> test(valid-describe): use dedent for multi-line cases (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/673">#673</a>)</li>
<li><a href="https://github.com/jest-community/eslint-plugin-jest/commit/8810d6730c7c6f83d39eb6efa1baa65ffb72478e"><code>8810d67</code></a> test(no-if): use dedent for all cases (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/671">#671</a>)</li>
<li><a href="https://github.com/jest-community/eslint-plugin-jest/commit/57ef99f1fabf4a03c893d92e94a494b1289fa362"><code>57ef99f</code></a> chore(deps): lock file maintenance (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/668">#668</a>)</li>
<li><a href="https://github.com/jest-community/eslint-plugin-jest/commit/a3ede080bfb456cd10b00a3ccdbdf160f702d0d0"><code>a3ede08</code></a> chore(deps): update commitlint monorepo to v11 (major) (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/667">#667</a>)</li>
<li><a href="https://github.com/jest-community/eslint-plugin-jest/commit/2f28a74e7dbb4e0df316e683719a28deb5677582"><code>2f28a74</code></a> chore(release): 24.0.1 [skip ci]</li>
<li><a href="https://github.com/jest-community/eslint-plugin-jest/commit/f636021c16215a713845c699858a2978211df49d"><code>f636021</code></a> fix: don't include deprecated rules in <code>all</code> config (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/664">#664</a>)</li>
<li><a href="https://github.com/jest-community/eslint-plugin-jest/commit/d16b84c23acda12d95244968313dc60396369b31"><code>d16b84c</code></a> docs(readme): add note about <code>jest/globals</code> being set by configs (<a href="https://github-redirect.dependabot.com/jest-community/eslint-plugin-jest/issues/659">#659</a>)</li>
<li>See full diff in <a href="https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.0...v24.0.2">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=eslint-plugin-jest&package-manager=npm_and_yarn&previous-version=24.0.0&new-version=24.0.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/configuring-github-dependabot-security-updates)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

codecov[bot]: # [Codecov](https://codecov.io/gh/googlemaps/js-api-loader/pull/56?src=pr&el=h1) Report
> Merging [#56](https://codecov.io/gh/googlemaps/js-api-loader/pull/56?src=pr&el=desc) into [master](https://codecov.io/gh/googlemaps/js-api-loader/commit/caffe67d7b989af3a1c7f4a1a6c79bd9fb2b4eb0?el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/googlemaps/js-api-loader/pull/56/graphs/tree.svg?width=650&height=150&src=pr&token=aAmgcWFXMs)](https://codecov.io/gh/googlemaps/js-api-loader/pull/56?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##            master       #56   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           74        74           
  Branches        10        10           
=========================================
  Hits            74        74           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/googlemaps/js-api-loader/pull/56?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/googlemaps/js-api-loader/pull/56?src=pr&el=footer). Last update [caffe67...146bed3](https://codecov.io/gh/googlemaps/js-api-loader/pull/56?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index f9c31c3..678efda 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -38,3 +38,15 @@ jobs:
         env:
           GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
           NPM_TOKEN: ${{ secrets.NPM_WOMBAT_TOKEN }}
+      - run: |        
+          npm i
+          npm run docs
+          cp -r dist docs/dist
+          cp -r examples docs/examples
+      - uses: peaceiris/actions-gh-pages@v3
+        with:
+          github_token: ${{ secrets.GITHUB_TOKEN }}
+          publish_dir: ./docs
+          user_name: 'googlemaps-bot'
+          user_email: 'googlemaps-bot@users.noreply.github.com'
+          commit_message: ${{ github.event.head_commit.message }}
diff --git a/.releaserc b/.releaserc
new file mode 100644
index 0000000..8343600
--- /dev/null
+++ b/.releaserc
@@ -0,0 +1,8 @@
+plugins:
+  - "@semantic-release/commit-analyzer"
+  - "@semantic-release/release-notes-generator"
+  - "@semantic-release/github"
+  - "@semantic-release/npm"
+  - "@semantic-release/git"
+options:
+  debug: true
diff --git a/package-lock.json b/package-lock.json
index 4734901..2e47ef2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "@googlemaps/js-api-loader",
-  "version": "1.0.0",
+  "version": "1.4.1",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
@@ -2760,9 +2760,9 @@
       }
     },
     "@types/jest": {
-      "version": "26.0.10",
-      "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.10.tgz",
-      "integrity": "sha512-i2m0oyh8w/Lum7wWK/YOZJakYF8Mx08UaKA1CtbmFeDquVhAEdA7znacsVSf2hJ1OQ/OfVMGN90pw/AtzF8s/Q==",
+      "version": "26.0.14",
+      "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.14.tgz",
+      "integrity": "sha512-Hz5q8Vu0D288x3iWXePSn53W7hAjP0H7EQ6QvDO9c7t46mR0lNOLlfuwQ+JkVxuhygHzlzPX+0jKdA3ZgSh+Vg==",
       "dev": true,
       "requires": {
         "jest-diff": "^25.2.1",
@@ -2899,15 +2899,15 @@
       }
     },
     "@typescript-eslint/experimental-utils": {
-      "version": "4.0.1",
-      "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.0.1.tgz",
-      "integrity": "sha512-gAqOjLiHoED79iYTt3F4uSHrYmg/GPz/zGezdB0jAdr6S6gwNiR/j7cTZ8nREKVzMVKLd9G3xbg1sV9GClW3sw==",
+      "version": "4.1.1",
+      "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.1.1.tgz",
+      "integrity": "sha512-jzYsNciHoa4Z3c1URtmeT/bamYm8Dwfw6vuN3WHIE/BXb1iC4KveAnXDErTAZtPVxTYBaYn3n2gbt6F6D2rm1A==",
       "dev": true,
       "requires": {
         "@types/json-schema": "^7.0.3",
-        "@typescript-eslint/scope-manager": "4.0.1",
-        "@typescript-eslint/types": "4.0.1",
-        "@typescript-eslint/typescript-estree": "4.0.1",
+        "@typescript-eslint/scope-manager": "4.1.1",
+        "@typescript-eslint/types": "4.1.1",
+        "@typescript-eslint/typescript-estree": "4.1.1",
         "eslint-scope": "^5.0.0",
         "eslint-utils": "^2.0.0"
       },
@@ -2980,29 +2980,29 @@
       }
     },
     "@typescript-eslint/scope-manager": {
-      "version": "4.0.1",
-      "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.0.1.tgz",
-      "integrity": "sha512-u3YEXVJ8jsj7QCJk3om0Y457fy2euEOkkzxIB/LKU3MdyI+FJ2gI0M4aKEaXzwCSfNDiZ13a3lDo5DVozc+XLQ==",
+      "version": "4.1.1",
+      "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.1.1.tgz",
+      "integrity": "sha512-0W8TTobCvIIQ2FsrYTffyZGAAFUyIbEHq5EYJb1m7Rpd005jrnOvKOo8ywCLhs/Bm17C+KsrUboBvBAARQVvyA==",
       "dev": true,
       "requires": {
-        "@typescript-eslint/types": "4.0.1",
-        "@typescript-eslint/visitor-keys": "4.0.1"
+        "@typescript-eslint/types": "4.1.1",
+        "@typescript-eslint/visitor-keys": "4.1.1"
       }
     },
     "@typescript-eslint/types": {
-      "version": "4.0.1",
-      "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.0.1.tgz",
-      "integrity": "sha512-S+gD3fgbkZYW2rnbjugNMqibm9HpEjqZBZkTiI3PwbbNGWmAcxolWIUwZ0SKeG4Dy2ktpKKaI/6+HGYVH8Qrlg==",
+      "version": "4.1.1",
+      "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.1.1.tgz",
+      "integrity": "sha512-zrBiqOKYerMTllKcn+BP+i1b7LW/EbMMYytroXMxUTvFPn1smkCu0D7lSAx29fTUO4jnwV0ljSvYQtn2vNrNxA==",
       "dev": true
     },
     "@typescript-eslint/typescript-estree": {
-      "version": "4.0.1",
-      "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.0.1.tgz",
-      "integrity": "sha512-zGzleORFXrRWRJAMLTB2iJD1IZbCPkg4hsI8mGdpYlKaqzvKYSEWVAYh14eauaR+qIoZVWrXgYSXqLtTlxotiw==",
+      "version": "4.1.1",
+      "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.1.1.tgz",
+      "integrity": "sha512-2AUg5v0liVBsqbGxBphbJ0QbGqSRVaF5qPoTPWcxop+66vMdU1h4CCvHxTC47+Qb+Pr4l2RhXDd41JNpwcQEKw==",
       "dev": true,
       "requires": {
-        "@typescript-eslint/types": "4.0.1",
-        "@typescript-eslint/visitor-keys": "4.0.1",
+        "@typescript-eslint/types": "4.1.1",
+        "@typescript-eslint/visitor-keys": "4.1.1",
         "debug": "^4.1.1",
         "globby": "^11.0.1",
         "is-glob": "^4.0.1",
@@ -3040,12 +3040,12 @@
       }
     },
     "@typescript-eslint/visitor-keys": {
-      "version": "4.0.1",
-      "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.0.1.tgz",
-      "integrity": "sha512-yBSqd6FjnTzbg5RUy9J+9kJEyQjTI34JdGMJz+9ttlJzLCnGkBikxw+N5n2VDcc3CesbIEJ0MnZc5uRYnrEnCw==",
+      "version": "4.1.1",
+      "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.1.1.tgz",
+      "integrity": "sha512-/EOOXbA2ferGLG6RmCHEQ0lTTLkOlXYDgblCmQk3tIU7mTPLm4gKhFMeeUSe+bcchTUsKeCk8xcpbop5Zr/8Rw==",
       "dev": true,
       "requires": {
-        "@typescript-eslint/types": "4.0.1",
+        "@typescript-eslint/types": "4.1.1",
         "eslint-visitor-keys": "^2.0.0"
       },
       "dependencies": {
@@ -4259,9 +4259,9 @@
       }
     },
     "eslint-plugin-jest": {
-      "version": "24.0.0",
-      "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-24.0.0.tgz",
-      "integrity": "sha512-a0G7hSDbuBCW4PNT6MVpAyfnGbUDOqxzOyhR6wT2BIBnR7MhvfAqd6KKfsTjX+Z3gxzIHiEsihzdClU4cSc6qQ==",
+      "version": "24.0.2",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-24.0.2.tgz",
+      "integrity": "sha512-DSBLNpkKDOpUJQkTGSs5sVJWsu0nDyQ2rYxkr0Eh7nrkc5bMUr/dlDbtTj3l8y6UaCVsem6rryF1OZrKnz1S5g==",
       "dev": true,
       "requires": {
         "@typescript-eslint/experimental-utils": "^4.0.1"
@@ -7426,9 +7426,9 @@
       "dev": true
     },
     "prettier": {
-      "version": "2.1.1",
-      "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.1.tgz",
-      "integrity": "sha512-9bY+5ZWCfqj3ghYBLxApy2zf6m+NJo5GzmLTpr9FsApsfjriNnS2dahWReHMi7qNPhhHl9SYHJs2cHZLgexNIw==",
+      "version": "2.1.2",
+      "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz",
+      "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==",
       "dev": true
     },
     "pretty-format": {
diff --git a/package.json b/package.json
index 31eeac6..1210dcf 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@googlemaps/js-api-loader",
-  "version": "1.0.0",
+  "version": "1.4.1",
   "description": "Wrapper for the loading of Google Maps JavaScript API script in the browser",
   "keywords": [
     "google",
diff --git a/src/index.ts b/src/index.ts
index 733be02..35ed926 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -23,7 +23,13 @@ declare global {
   }
 }
 
-type Libraries = ("drawing" | "geometry" | "localContext" | "places" | "visualization")[];
+type Libraries = (
+  | "drawing"
+  | "geometry"
+  | "localContext"
+  | "places"
+  | "visualization"
+)[];
 
 /**
  * The Google Maps JavaScript API
@@ -65,6 +71,10 @@ export interface LoaderOptions {
    * receive your default channel.
    */
   version?: string;
+  /**
+   * The id of the script tag. Before adding a new script, the Loader will check for an existing one.
+   */
+  id?: string;
   /**
    * When loading the Maps JavaScript API via the URL you may optionally load
    * additional libraries through use of the libraries URL parameter. Libraries
@@ -130,6 +140,10 @@ export interface LoaderOptions {
    * your bootstrap request.
    */
   mapIds?: string[];
+  /**
+   * Use a custom url and path to load the Google Maps API script.
+   */
+  url?: string;
 }
 
 /**
@@ -160,6 +174,10 @@ export class Loader {
    * See [[LoaderOptions.apiKey]]
    */
   apiKey: string;
+  /**
+   * See [[LoaderOptions.id]]
+   */
+  id: string;
   /**
    * See [[LoaderOptions.libraries]]
    */
@@ -179,8 +197,12 @@ export class Loader {
    */
   mapIds: string[];
 
+  /**
+   * See [[LoaderOptions.url]]
+   */
+  url: string;
+
   private CALLBACK = "__googleMapsCallback";
-  private URL = "https://maps.googleapis.com/maps/api/js";
   private callbacks: ((e: Event) => void)[] = [];
   private done = false;
   private loading = false;
@@ -197,18 +219,22 @@ export class Loader {
    */
   constructor({
     apiKey,
+    id = "__googleMapsScriptId",
     libraries = [],
     language,
     region,
     version,
     mapIds,
+    url = "https://maps.googleapis.com/maps/api/js",
   }: LoaderOptions) {
     this.version = version;
     this.apiKey = apiKey;
+    this.id = id;
     this.libraries = libraries;
     this.language = language;
     this.region = region;
     this.mapIds = mapIds;
+    this.url = url;
   }
   /**
    * CreateUrl returns the Google Maps JavaScript API script url given the [[LoaderOptions]].
@@ -216,7 +242,7 @@ export class Loader {
    * @ignore
    */
   createUrl(): string {
-    let url = this.URL;
+    let url = this.url;
 
     url += `?callback=${this.CALLBACK}`;
 
@@ -283,9 +309,14 @@ export class Loader {
    * Set the script on document.
    */
   private setScript(): void {
+    if (this.id && document.getElementById(this.id)) {
+      this.callback();
+      return;      
+    }
+    
     const url = this.createUrl();
     const script = document.createElement("script");
-
+    script.id = this.id;
     script.type = "text/javascript";
     script.src = url;
     script.onerror = this.loadErrorCallback.bind(this);


Test patch:
diff --git a/src/index.test.ts b/src/index.test.ts
index de5f0d7..727cff2 100644
--- a/src/index.test.ts
+++ b/src/index.test.ts
@@ -16,6 +16,10 @@
 
 import { Loader, LoaderOptions } from ".";
 
+afterEach(() => {
+  document.getElementsByTagName('html')[0].innerHTML = ''; 
+});
+
 test.each([
   [{}, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback"],
   [
@@ -36,6 +40,10 @@ test.each([
     { mapIds: ["foo", "bar"] },
     "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&map_ids=foo,bar",
   ],
+  [
+    { url: "https://example.com/js" },
+    "https://example.com/js?callback=__googleMapsCallback",
+  ],
 ])("createUrl is correct", (options: LoaderOptions, expected: string) => {
   const loader = new Loader(options);
   expect(loader.createUrl()).toEqual(expected);
@@ -48,6 +56,7 @@ test("setScript adds a script to head with correct attributes", () => {
 
   const script = document.head.childNodes[0] as HTMLScriptElement;
 
+  expect(script.id).toEqual(loader.id);
   expect(script.src).toEqual(loader.createUrl());
   expect(script.defer).toBeTruthy();
   expect(script.async).toBeTruthy();
@@ -55,6 +64,21 @@ test("setScript adds a script to head with correct attributes", () => {
   expect(script.type).toEqual("text/javascript");
 });
 
+test("setScript does not add second script with same id", () => {
+  new Loader({ apiKey: "foo", id: "bar" })['setScript']();
+  new Loader({ apiKey: "foo", id: "bar" })['setScript']();
+
+  expect(document.head.childNodes.length).toBe(1);
+});
+
+test("setScript adds a script with id", () => {
+  const loader = new Loader({ apiKey: "foo", id: "bar" });
+  loader["setScript"]();
+
+  const script = document.head.childNodes[0] as HTMLScriptElement;
+  expect(script.id).toEqual(loader.id);
+});
+
 test("load should return a promise that resolves even if called twice", () => {
   const loader = new Loader({ apiKey: "foo" });