Skip to content

Commit

Permalink
fix: properly handle import modules with .vue suffix (#420)
Browse files Browse the repository at this point in the history
Closes: #416
  • Loading branch information
piotr-oles committed May 26, 2020
1 parent 1ff3ce4 commit cfcc0fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/typescript-reporter/extension/TypeScriptEmbeddedExtension.ts
Expand Up @@ -50,22 +50,10 @@ function createTypeScriptEmbeddedExtension({
type FileExists = (fileName: string) => boolean;
function createEmbeddedFileExists(fileExists: FileExists): FileExists {
return function embeddedFileExists(fileName) {
const { embeddedExtension, embeddedFileName, extension } = parsePotentiallyEmbeddedFileName(
fileName
);

if (embeddedExtensions.includes(embeddedExtension)) {
const embeddedSource = getCachedEmbeddedSource(embeddedFileName);
const { embeddedExtension, embeddedFileName } = parsePotentiallyEmbeddedFileName(fileName);

// we return true only if file extension matches extension returned by the getEmbeddedSource method.
// we assume that there is a regular TypeScript resolveModuleName implementation that runs fileExists
// for files with all TypeScript supported extensions (.ts, .d.ts, .tsx, .js)
if (embeddedSource && embeddedSource.extension === extension) {
// already checked if file exists in the getEmbeddedSource call.
// we can assume that file still exists because we are relying on the watch mechanism
// which removes cache entry on any file change
return true;
}
if (embeddedExtensions.includes(embeddedExtension) && fileExists(embeddedFileName)) {
return true;
}

return fileExists(fileName);
Expand Down
1 change: 1 addition & 0 deletions test/e2e/fixtures/environment/typescript-vue.fixture
Expand Up @@ -18,6 +18,7 @@
"typescript": ${TYPESCRIPT_VERSION},
"vue-loader": "^15.8.3",
"vue-template-compiler": "^2.6.11",
"qrcode.vue": "^1.7.0",
"webpack": ${WEBPACK_VERSION},
"webpack-cli": ${WEBPACK_CLI_VERSION},
"webpack-dev-server": ${WEBPACK_DEV_SERVER_VERSION}
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/fixtures/implementation/typescript-vue.fixture
Expand Up @@ -41,19 +41,23 @@ export default class App extends Vue {
<input v-model="email" name="email" type="email" />
<input v-model="password" name="password" type="password" />

<qrcode-vue :value="url"></qrcode-vue>

<button type="submit" v-bind:disabled="pending">Login</button>
</form>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import QrcodeVue from "qrcode.vue";

@Component
export default class LoginForm extends Vue {
public email = '';
public password = '';
public pending = false;
public url = 'http://my-site.com/login';

async login() {
try {
Expand Down

0 comments on commit cfcc0fe

Please sign in to comment.